-
Notifications
You must be signed in to change notification settings - Fork 30
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
Fixed bug in mapping parsing; added tests #1023
Conversation
Signed-off-by: Chris Helma <chelma+github@amazon.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1023 +/- ##
============================================
- Coverage 80.20% 80.19% -0.02%
Complexity 2722 2722
============================================
Files 365 365
Lines 13603 13606 +3
Branches 941 942 +1
============================================
+ Hits 10910 10911 +1
- Misses 2118 2119 +1
- Partials 575 576 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Signed-off-by: Chris Helma <chelma+github@amazon.com>
@@ -75,17 +76,21 @@ public static void removeIntermediateMappingsLevels(ObjectNode root) { | |||
* - [{"doc":{"properties":{"address":{"type":"text"}}}}] | |||
* - [{"audit_message":{"properties":{"address":{"type":"text"}}}}] | |||
* | |||
* It's not impossible that the intermediate key is not present, in which case we should just extract the mappings: | |||
* It's also possible for this list to be empty, in which case we should set the mappings to an empty node. |
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.
Why is it appropriate to replace [] with "[{}]". Is this true for all versions of targets?
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 results in an index creation call that looks like:
curl -X PUT "localhost:92011/index_name" -H "Content-Type: application/json" -d '
{
"settings": {
<the settings>
},
"mappings": {
}
}'
I'm not sure if the empty mappings blob is valid for ALL possible targets, but it does appear valid for the targets we currently consider - OS 1.X & OS 2.X
ObjectNode testNode1 = new ObjectMapper().createObjectNode(); | ||
ArrayNode mappingsNode1 = new ObjectMapper().createArrayNode(); | ||
ObjectNode docNode1 = new ObjectMapper().createObjectNode(); | ||
ObjectNode propertiesNode1 = new ObjectMapper().createObjectNode(); | ||
ObjectNode addressNode1 = new ObjectMapper().createObjectNode(); | ||
addressNode1.put("type", "text"); | ||
propertiesNode1.set("address", addressNode1); | ||
docNode1.set(TransformFunctions.PROPERTIES_KEY_STR, propertiesNode1); | ||
ObjectNode intermediateNode1 = new ObjectMapper().createObjectNode(); | ||
intermediateNode1.set("_doc", docNode1); | ||
mappingsNode1.add(intermediateNode1); |
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.
could you replace this w/ inline json that gets parsed?
var json =
"{" +
" \"mappings\": [{" +
" \"_doc\": {" +
...
It's a lot easier to read and to maintain. You can copy-paste literal json from a text editor into your IDE and it should do all of the necessary escaping (IntelliJ does this, I'd hope eclipse & vscode do too).
Then you can just new ObjectMapper().readTree(json)
and get the parsed JsonNode back.
curl -X PUT "localhost:19200/no_mappings_no_docs" -H "Content-Type: application/json" -d ' | ||
{ | ||
"settings": { | ||
"index": { | ||
"number_of_shards": 1, | ||
"number_of_replicas": 0 | ||
} | ||
} | ||
}' | ||
|
||
curl -X PUT "localhost:19200/empty_mappings_no_docs" -H "Content-Type: application/json" -d ' | ||
{ | ||
"settings": { | ||
"index": { | ||
"number_of_shards": 1, | ||
"number_of_replicas": 0 | ||
} | ||
}, | ||
"mappings": { | ||
"properties":{ | ||
} | ||
} | ||
}' |
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.
I'd love to see us generate these on-the-fly and then cache them like we do for preloaded data images. In fact, use the preloaded images, then just take a snapshot via a helper program. Make the output of that something that gets cached as a build artifact and then it can become a dependency to the tests. It seems like that could be 1-2 hours of work and removes the risks of many hours of work trying to figure out if there was a mismatch later on.
Description
Issues Resolved
Testing
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.