-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Make sure to reject mappings with type _doc when include_type_name is false. #38270
Make sure to reject mappings with type _doc when include_type_name is false. #38270
Conversation
Pinging @elastic/es-search |
Pinging @elastic/es-core-features |
2bbf871
to
82066cf
Compare
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 left some minor comments but in general it looks good to me. Thanks for extracting the map manipulation code to functions that can be unit-tested.
version: " - 6.99.99" | ||
reason: include_type_name defaults to true before 7.0 | ||
- do: | ||
catch: /illegal_argument_exception/ |
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.
can we match a more specific string in the error message?
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.
👍
index: test_index | ||
|
||
- do: | ||
catch: /illegal_argument_exception/ |
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.
can we match a more specific string in the error message?
reason: include_type_name defaults to true before 7.0 | ||
|
||
- do: | ||
catch: /illegal_argument_exception/ |
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.
can we match a more specific string in the error message?
|
||
|
||
static Map<String, Object> prepareMappings(Map<String, Object> source, boolean includeTypeName) { | ||
if (includeTypeName || !source.containsKey("mappings")) { |
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.
use == false for consistency with the rest of the codebase?
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.
Will do, this is proving a hard habit to break!
Map<String, Object> newSource = new HashMap<>(source); | ||
|
||
@SuppressWarnings("unchecked") | ||
Map<String, Object> mappings = (Map<String, Object>) source.get("mappings"); |
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 cast is unsafe and would result in a confusing error message if a user created an index with something like below? Should we have an instanceof Map
check?
PUT test
{
"mappings": "foo"
}
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.
Thanks, will fix this.
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.
Just a note that I made this method more robust, but after testing I noticed the same confusing error will occur even without these changes. This is because of another unchecked cast: https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java#L381
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.
Thanks for looking
Thank you @jpountz for reviewing, it is ready for another look. |
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
Map<String, Object> newSource = new HashMap<>(source); | ||
|
||
@SuppressWarnings("unchecked") | ||
Map<String, Object> mappings = (Map<String, Object>) source.get("mappings"); |
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.
Thanks for looking
* master: (23 commits) Lift retention lease expiration to index shard (elastic#38380) Make Ccr recovery file chunk size configurable (elastic#38370) Prevent CCR recovery from missing documents (elastic#38237) re-enables awaitsfixed datemath tests (elastic#38376) Types removal fix FullClusterRestartIT warnings (elastic#38445) Make sure to reject mappings with type _doc when include_type_name is false. (elastic#38270) Updates the grok patterns to be consistent with logstash (elastic#27181) Ignore type-removal warnings in XPackRestTestHelper (elastic#38431) testHlrcFromXContent() should respect assertToXContentEquivalence() (elastic#38232) add basic REST test for geohash_grid (elastic#37996) Remove DiscoveryPlugin#getDiscoveryTypes (elastic#38414) Fix the clock resolution to millis in GetWatchResponseTests (elastic#38405) Throw AssertionError when no master (elastic#38432) `if_seq_no` and `if_primary_term` parameters aren't wired correctly in REST Client's CRUD API (elastic#38411) Enable CronEvalToolTest.testEnsureDateIsShownInRootLocale (elastic#38394) Fix failures in BulkProcessorIT#testGlobalParametersAndBulkProcessor. (elastic#38129) SQL: Implement CURRENT_DATE (elastic#38175) Mute testReadRequestsReturnLatestMappingVersion (elastic#38438) [ML] Report index unavailable instead of waiting for lazy node (elastic#38423) Update Rollup Caps to allow unknown fields (elastic#38339) ...
elastic/elasticsearch#38270 made current master (7.0.0) reject mappings with type `_doc` unless `?include_type_name=true` is passed during index creation. Workaround the rejection for now by explicitly setting `include_type_name` to `true` in every create_index operation.
elastic/elasticsearch#38270 made current master (7.0.0) reject mappings with type `_doc` unless `?include_type_name=true` is passed during index creation. Workaround the rejection for now by explicitly setting `include_type_name` to `true` in every create_index operation. Relates: #64
CreateIndexRequest#source(Map<String, Object>, ... )
, which is used when deserializing index creation requests, accidentally accepts mappings that are nested twice under the type key (as described in the bug report #38266).This in turn causes us to be too lenient in parsing typeless mappings. In particular, we accept the following index creation request, even though it should not contain the type key
_doc
:There is a similar issue for both 'put templates' and 'put mappings' requests as well.
This PR makes the minimal changes to detect and reject these typed mappings in requests. It does not address #38266 generally, or attempt a larger refactor around types in these server-side requests, as I think this should be done at a later time.