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

Deprecate uses of _type as a field name in queries #36503

Conversation

mayya-sharipova
Copy link
Contributor

Relates to #35190

@mayya-sharipova mayya-sharipova added v7.0.0 >deprecation :Search Foundations/Mapping Index mappings, including merging and defining field types labels Dec 11, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@mayya-sharipova mayya-sharipova force-pushed the deprecate_reference_to_types_in_match_query branch from d9b7837 to 0947bad Compare December 11, 2018 20:23
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 @mayya-sharipova, the overall approach seems good to me! I left a few small comments.

@@ -823,10 +823,9 @@ public void testReindex() throws Exception {
// tag::reindex-request-conflicts
request.setConflicts("proceed"); // <1>
// end::reindex-request-conflicts
// tag::reindex-request-typeOrQuery
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should remove these reindex-related changes, and tackle them in a dedicated PR? I think there may be more updates to track down around the reindex API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jtibshirani Thanks Julie. The only reason I added these changes into this PR is because request.setSourceDocTypes("_doc"); underneath uses a query with a type that we are deprecating in this PR, and if I don't remove this line, CRUDDocumentationIT. :: testReindex fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, I missed that!

@@ -75,12 +75,18 @@ public void testFromJson() throws IOException {
@Override
public void testToQuery() throws IOException {
super.testToQuery();
assertWarnings("The [type] query is deprecated, filter on a field instead.");
assertWarnings(
"The [type] query is deprecated, filter on a field instead.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could avoid these duplicate warning messages? One idea:

  • We generalize the message in TypeFieldType.TYPES_DEPRECATION_MESSAGE to say "[types removal] Referring to types within search queries is deprecated, filter on a field instead."
  • We make sure to use deprecatedAndMaybeLog in TypeQueryBuilder to avoid producing the warning twice.

@@ -124,6 +125,7 @@ public boolean isSearchable() {

@Override
public Query existsQuery(QueryShardContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To be really comprehensive, we could also override the other query types (fuzzy, prefix, wildcard and regex) and issue deprecation warnings.

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 Julie. Turns out that fuzzy, prefix and regex query all fail on the _type field, as the field is not indexed. So these kind of requests are not allowed. wildcard query is calling termQuery underneath, so we should get an expected deprecation message.

public void testRangeQuery() {
QueryShardContext context = Mockito.mock(QueryShardContext.class);
MapperService mapperService = Mockito.mock(MapperService.class);
Mockito.when(mapperService.documentMapper()).thenReturn(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this line, since it's superseded by Mockito.when(mapperService.documentMapper()).thenReturn(mapper); below.

@mayya-sharipova
Copy link
Contributor Author

@jtibshirani Thanks for the feedback, Julie. I have tried to address your feedback, please continue to review when you have available time.

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.

It looks good to me. One small comment: maybe we could update the PR/ commit title to 'Deprecate uses of _type as a field name in queries', because this PR doesn't address type fields in aggregations or retrieved fields.

@mayya-sharipova mayya-sharipova changed the title Deprecate uses of _type as a field name Deprecate uses of _type as a field name in queries Dec 12, 2018
@mayya-sharipova
Copy link
Contributor Author

@elasticmachine test this please

@jtibshirani
Copy link
Contributor

From your most recent change, I saw that we'll now be emitting two deprecation warnings for some APIs. For example with 'explain', we'll have one for types in the explain URL, and one for the use of a type filter in search. I originally liked your approach because it colocates many deprecations into the same class TypeFieldMapper. But now I'm wondering if we should try to avoid these duplicate warnings, and move the deprecations elsewhere, for example in TermsQueryBuilder.fromXContent.

It might be good to get @markharwood or @cbuescher's thoughts here as well.

@mayya-sharipova mayya-sharipova merged commit d40037c into elastic:master Dec 13, 2018
@mayya-sharipova
Copy link
Contributor Author

@jtibshirani Julie, sorry I have noticed your comment after the merging. Let's discuss it tomorrow.

@mayya-sharipova
Copy link
Contributor Author

mayya-sharipova commented Dec 13, 2018

@jtibshirani I tried to investigate why an explain request on all docs needs to set up a filter on type. This happens here:
https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/search/DefaultSearchContext.java#L258-L274

I wonder if we can get rid of setting filter on type now that we have only a single type on all indexes.

Also, because we call this terms query on type internally, we don't go through TermsQueryBuilder.fromXContent

@jtibshirani
Copy link
Contributor

jtibshirani commented Dec 18, 2018

I don't think we can remove type filters altogether in 7.0, since users may be searching across multiple indices (containing multiple distinct types). However, we should be able to remove them in 8.0, once types are no longer supported.

I had a simple idea for an alternative -- I'll upload a PR so that we can discuss it.

An update: I opened #36802 with the alternate approach.

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

Successfully merging this pull request may close these issues.

None yet

4 participants