-
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
[Rest Api Compatibility] CommonTermsQuery and cutoff_frequency param #75896
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e246e41
[Rest Api Compatibility] Make query registration easier
pgomulka 0d66879
Merge remote-tracking branch 'upstream/master' into compat/named_xcon…
pgomulka deaee55
remove getNamedXContentForCompatibility
pgomulka 5341297
Merge remote-tracking branch 'upstream/master' into compat/named_xcon…
pgomulka 8b6452b
draft common term query
pgomulka 512de4b
tests
pgomulka 4ab0b16
Merge remote-tracking branch 'upstream/master' into compat/common_ter…
pgomulka 4f794c7
fix tests and messages
pgomulka 6aeaef4
Merge remote-tracking branch 'upstream/master' into compat/common_ter…
pgomulka 041fa99
import
pgomulka bb0d659
Merge remote-tracking branch 'upstream/master' into compat/common_ter…
pgomulka ad4be3f
rename
pgomulka 33da26d
unsupported opertaion exception
pgomulka 1d4b5b4
Merge remote-tracking branch 'upstream/master' into compat/common_ter…
pgomulka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...c/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/search/10_cutoff_frequency.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- | ||
setup: | ||
- skip: | ||
version: "9.0.0 - " | ||
reason: "compatible from 8.x to 7.x" | ||
features: | ||
- "headers" | ||
- "allowed_warnings_regex" | ||
- do: | ||
indices.create: | ||
index: "test" | ||
body: | ||
mappings: | ||
properties: | ||
my_field1: | ||
type: "text" | ||
my_field2: | ||
type: "text" | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" | ||
allowed_warnings_regex: | ||
- "\\[types removal\\].*" | ||
- do: | ||
index: | ||
index: "test" | ||
id: 1 | ||
body: | ||
my_field1: "brown fox jump" | ||
my_field2: "xylophone" | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" | ||
allowed_warnings_regex: | ||
- "\\[types removal\\].*" | ||
- do: | ||
indices.refresh: {} | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" | ||
allowed_warnings_regex: | ||
- "\\[types removal\\].*" | ||
|
||
--- | ||
multi_match multiple fields with cutoff_frequency throws exception: | ||
- do: | ||
catch: "/cutoff_freqency is not supported. The \\[multi_match\\] query can skip block of documents efficiently if the total number of hits is not tracked/" | ||
search: | ||
rest_total_hits_as_int: true | ||
index: "test" | ||
body: | ||
query: | ||
multi_match: | ||
query: "brown" | ||
type: "bool_prefix" | ||
fields: | ||
- "my_field1" | ||
- "my_field2" | ||
cutoff_frequency: 0.001 | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" | ||
allowed_warnings_regex: | ||
- "\\[types removal\\].*" | ||
|
||
--- | ||
match with cutoff_frequency throws exception: | ||
- do: | ||
catch: "/cutoff_freqency is not supported. The \\[match\\] query can skip block of documents efficiently if the total number of hits is not tracked/" | ||
search: | ||
rest_total_hits_as_int: true | ||
index: "test" | ||
body: | ||
query: | ||
match: | ||
my_field1: | ||
query: "brown" | ||
type: "bool_prefix" | ||
cutoff_frequency: 0.001 | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" | ||
allowed_warnings_regex: | ||
- "\\[types removal\\].*" | ||
|
||
--- | ||
common querythrows exception: | ||
- do: | ||
catch: "/Common Terms Query usage is not supported. Use \\[match\\] query which can efficiently skip blocks of documents if the total number of hits is not tracked./" | ||
search: | ||
rest_total_hits_as_int: true | ||
index: "test" | ||
body: | ||
query: | ||
common: | ||
my_field1: | ||
query: "brown" | ||
type: "bool_prefix" | ||
cutoff_frequency: 0.001 | ||
low_freq_operator: or | ||
headers: | ||
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" | ||
Accept: "application/vnd.elasticsearch+json;compatible-with=7" | ||
allowed_warnings_regex: | ||
- "\\[types removal\\].*" |
65 changes: 65 additions & 0 deletions
65
server/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.index.query; | ||
|
||
import org.apache.lucene.search.Query; | ||
import org.elasticsearch.common.ParsingException; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.logging.DeprecationLogger; | ||
import org.elasticsearch.common.xcontent.ParseField; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.core.RestApiVersion; | ||
|
||
import java.io.IOException; | ||
|
||
public class CommonTermsQueryBuilder extends AbstractQueryBuilder<CommonTermsQueryBuilder> { | ||
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(CommonTermsQueryBuilder.class); | ||
public static final String COMMON_TERMS_QUERY_DEPRECATION_MSG = "Common Terms Query usage is not supported. " + | ||
"Use [match] query which can efficiently skip blocks of documents if the total number of hits is not tracked."; | ||
|
||
public static ParseField NAME_V7 = new ParseField("common") | ||
.withAllDeprecated(COMMON_TERMS_QUERY_DEPRECATION_MSG) | ||
.forRestApiVersion(RestApiVersion.equalTo(RestApiVersion.V_7)); | ||
|
||
@Override | ||
protected void doWriteTo(StreamOutput out) throws IOException { | ||
throw new UnsupportedOperationException("common_term_query is not meant to be serialized."); | ||
} | ||
|
||
@Override | ||
protected void doXContent(XContentBuilder builder, Params params) throws IOException { | ||
} | ||
|
||
@Override | ||
protected Query doToQuery(SearchExecutionContext context) throws IOException { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected boolean doEquals(CommonTermsQueryBuilder other) { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected int doHashCode() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return null; | ||
} | ||
|
||
public static CommonTermsQueryBuilder fromXContent(XContentParser parser) throws IOException { | ||
deprecationLogger.compatibleApiWarning("common_term_query", COMMON_TERMS_QUERY_DEPRECATION_MSG); | ||
throw new ParsingException(parser.getTokenLocation(), COMMON_TERMS_QUERY_DEPRECATION_MSG); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 throw UnsupportedOperationException here to make sure we catch inadvertent calls early?