Skip to content
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

Add an include_type_name option to 6.x. (#29453) #37147

Merged
merged 4 commits into from
Jan 9, 2019

Conversation

jpountz
Copy link
Contributor

@jpountz jpountz commented Jan 4, 2019

This adds an include_type_name option to the indices.create,
indices.get_mapping and indices.put_mapping APIs, which defaults to true.
When set to false, then mappings will be returned directly in the body of
the indices.get_mapping API, without keying them by the type name, the
indices.create will expect mappings directly under the mappings key, and
the indices.put_mapping will use _doc as a type name and fail if a type
is provided explicitly.

On 5.x indices, get-mapping will fail if the index has multiple mappings, and
put-mapping will update or introduce mappings for the _doc type instead of
updating existing mappings. This oddity is required so that we don't have to
introduce a new flag to put-mapping requests to know whether they are actually
updating the _doc type or performing a typeless call.

Relates #35190

This adds an `include_type_name` option to the `indices.create`,
`indices.get_mapping` and `indices.put_mapping` APIs, which defaults to `true`.
When set to `false`, then mappings will be returned directly in the body of
the `indices.get_mapping` API, without keying them by the type name, the
`indices.create` will expect mappings directly under the `mappings` key, and
the `indices.put_mapping` will use `_doc` as a type name and fail if a `type`
is provided explicitly.

On 5.x indices, get-mapping will fail if the index has multiple mappings, and
put-mapping will update or introduce mappings for the `_doc` type instead of
updating existing mappings. This oddity is required so that we don't have to
introduce a new flag to put-mapping requests to know whether they are actually
updating the `_doc` type or performing a typeless call.

Relates elastic#15613
@jpountz jpountz added >feature :Search Foundations/Mapping Index mappings, including merging and defining field types v6.7.0 labels Jan 4, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jpountz ! I initially had a question about the upgrade path, but deleted it as I was able to resolve it.

@@ -13,6 +13,10 @@
}
},
"params": {
"include_type_name": {
"type" : "string",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be of type "boolean"? I guess we have the same issue on 7.0, so we could fix this separately if you prefer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a commit to this branch to fix this. I also have a PR open on master to apply the same change there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -0,0 +1,23 @@
---
"GET mapping with typeless API on an index that has types":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also backport the test changes to the standard rest tests (10_basic, 11_basic_with_types, etc.)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also pushed a commit to add these tests.

@@ -239,6 +241,21 @@ public void refreshMapping(final String index, final String indexUUID) {
}
}

private DocumentMapper getMapperForUpdate(MapperService mapperService, String type) {
DocumentMapper mapper = mapperService.documentMapper(type);
if (mapper == null && type.equals(MapperService.SINGLE_MAPPING_NAME) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking the index version here, would it make sense to check if the index has multiple mappings? That would be consistent with how typeless 'get mappings' works on indices with multiple types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what my first version of this PR did but then I had test failures because some tests initially set up a type with a 5.x index and then index documents with the _doc type. It's probably a test bug, but thinking about this case made me unhappy that using the typeless API with a 5.x index would introduce a new type on 6.6 and reuse the existing type on 6.7, which might be surprising. 6.x indices are less problematic in my opinion since typeless API calls were rejected on previous versions, so it's more unlikely to be something that users relied on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing to have in mind is that 5.x indices can't be read by Elasticsearch 7.x anyway due to our backward compatibility policy that only supports reading indices created by version N or N-1. So 5.x indices would have to be reindexed prior to upgrading anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this reasoning makes sense to me as well.

@jtibshirani jtibshirani requested a review from cbuescher January 9, 2019 05:02
@jtibshirani
Copy link
Contributor

@elasticmachine run gradle build tests 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>feature :Search Foundations/Mapping Index mappings, including merging and defining field types v6.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants