-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Enrich validate nested mappings #42452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enrich validate nested mappings #42452
Conversation
|
Pinging @elastic/es-core-features |
martijnvg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. I left a few comments.
|
|
||
| private ActionListener<PolicyExecutionResult> createTestListener(final CountDownLatch latch, | ||
| final Consumer<Exception> exceptionConsumer) { | ||
| return new ActionListener<>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use LatchedActionListener and ActionListener#wrap(...) instead?
| // Ensure that the current field is of object type only (not a nested type or a non compound field) | ||
| Object type = currentField.get("type"); | ||
| if (type != null) { | ||
| throw new ElasticsearchException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an object field can be specifically configured with: type: object, so we need to check for this here
| .endObject() | ||
| .startObject("field3") | ||
| .field("type", "keyword") | ||
| .endObject() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also add a test that has a mapping with two nested object fields (level1.level2.*)?
| assertThat(shard.getSegments().size(), is(equalTo(1))); | ||
| Segment segment = shard.getSegments().iterator().next(); | ||
| assertThat(segment.getNumDocs(), is(equalTo(3))); | ||
| assertThat(segment.getNumDocs(), is(equalTo(expectedDocs))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also add a thing test that configures object fields with a type (type: object)?
martijnvg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
hub-cap
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nits
| } | ||
|
|
||
| private void validateField(Map<?, ?> properties, String fieldName, boolean fieldRequired) { | ||
| assert fieldName != null && !fieldName.isEmpty() : "Field name cannot be null or empty"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert Strings.isEmpty(fieldName) == false: "..";
| for (String fieldPart : fieldParts) { | ||
| // Ensure that the current field is of object type only (not a nested type or a non compound field) | ||
| Object type = currentField.get("type"); | ||
| if (type != null && !"object".equals(type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"object".equals(type) == false
|
|
||
| // Validate Mapping | ||
| Map<String, Object> mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); | ||
| logger.info(mapping); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this meant to be here?
Ensures that fields retained in an enrich index from a source are not contained under a nested field. It additionally makes sure that key fields exist, and that value fields are checked if they are present. The policy runner test has also been expanded with some faulty mapping test cases.
This PR ensures that fields retained in an enrich index from a source are not contained under a nested field. It additionally makes sure that key fields exist, and that value fields are checked if they are present. The policy runner test has also been expanded with some faulty mapping test cases.