diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java index 51670b29de1b6..3530e63e47e1d 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/QueryDSLDocumentationTests.java @@ -42,7 +42,6 @@ import static java.util.Collections.singletonMap; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.boostingQuery; -import static org.elasticsearch.index.query.QueryBuilders.commonTermsQuery; import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery; import static org.elasticsearch.index.query.QueryBuilders.disMaxQuery; import static org.elasticsearch.index.query.QueryBuilders.existsQuery; @@ -106,13 +105,6 @@ public void testBoosting() { // end::boosting } - public void testCommonTerms() { - // tag::common_terms - commonTermsQuery("name", // <1> - "kimchy"); // <2> - // end::common_terms - } - public void testConstantScore() { // tag::constant_score constantScoreQuery( diff --git a/docs/java-rest/high-level/query-builders.asciidoc b/docs/java-rest/high-level/query-builders.asciidoc index 53d9b9af97d12..f845a8c32e602 100644 --- a/docs/java-rest/high-level/query-builders.asciidoc +++ b/docs/java-rest/high-level/query-builders.asciidoc @@ -23,7 +23,6 @@ This page lists all the available search queries with their corresponding `Query | {ref}/query-dsl-match-query-phrase.html[Match Phrase] | {query-ref}/MatchPhraseQueryBuilder.html[MatchPhraseQueryBuilder] | {query-ref}/QueryBuilders.html#matchPhraseQuery-java.lang.String-java.lang.Object-[QueryBuilders.matchPhraseQuery()] | {ref}/query-dsl-match-query-phrase-prefix.html[Match Phrase Prefix] | {query-ref}/MatchPhrasePrefixQueryBuilder.html[MatchPhrasePrefixQueryBuilder] | {query-ref}/QueryBuilders.html#matchPhrasePrefixQuery-java.lang.String-java.lang.Object-[QueryBuilders.matchPhrasePrefixQuery()] | {ref}/query-dsl-multi-match-query.html[Multi Match] | {query-ref}/MultiMatchQueryBuilder.html[MultiMatchQueryBuilder] | {query-ref}/QueryBuilders.html#multiMatchQuery-java.lang.Object-java.lang.String\…-[QueryBuilders.multiMatchQuery()] -| {ref}/query-dsl-common-terms-query.html[Common Terms] | {query-ref}/CommonTermsQueryBuilder.html[CommonTermsQueryBuilder] | {query-ref}/QueryBuilders.html#commonTermsQuery-java.lang.String-java.lang.Object-[QueryBuilders.commonTermsQuery()] | {ref}/query-dsl-query-string-query.html[Query String] | {query-ref}/QueryStringQueryBuilder.html[QueryStringQueryBuilder] | {query-ref}/QueryBuilders.html#queryStringQuery-java.lang.String-[QueryBuilders.queryStringQuery()] | {ref}/query-dsl-simple-query-string-query.html[Simple Query String] | {query-ref}/SimpleQueryStringBuilder.html[SimpleQueryStringBuilder] | {query-ref}/QueryBuilders.html#simpleQueryStringQuery-java.lang.String-[QueryBuilders.simpleQueryStringQuery()] |====== diff --git a/docs/reference/migration/migrate_8_0.asciidoc b/docs/reference/migration/migrate_8_0.asciidoc index b697abf9a9f25..d1a68ba8f7933 100644 --- a/docs/reference/migration/migrate_8_0.asciidoc +++ b/docs/reference/migration/migrate_8_0.asciidoc @@ -24,6 +24,7 @@ coming[8.0.0] * <> * <> * <> +* <> * <> //NOTE: The notable-breaking-changes tagged regions are re-used in the @@ -60,4 +61,5 @@ include::migrate_8_0/node.asciidoc[] include::migrate_8_0/transport.asciidoc[] include::migrate_8_0/http.asciidoc[] include::migrate_8_0/reindex.asciidoc[] +include::migrate_8_0/search.asciidoc[] include::migrate_8_0/settings.asciidoc[] diff --git a/docs/reference/migration/migrate_8_0/search.asciidoc b/docs/reference/migration/migrate_8_0/search.asciidoc index 82886d35bc6a5..6fba2970f593e 100644 --- a/docs/reference/migration/migrate_8_0/search.asciidoc +++ b/docs/reference/migration/migrate_8_0/search.asciidoc @@ -7,4 +7,16 @@ The `/{index}/{type}/_search`, `/{index}/{type}/_msearch`, `/{index}/{type}/_search/template` and `/{index}/{type}/_msearch/template` REST endpoints have been removed in favour of `/{index}/_search`, `/{index}/_msearch`, `/{index}/_search/template` and `/{index}/_msearch/template`, since indexes no longer contain types, these typed endpoints are obsolete.. -The `/{index}/{type}/_termvectors`, `/{index}/{type}/{id}/_termvectors` and `/{index}/{type}/_mtermvectors` REST endpoints have been removed in favour of `/{index}/_termvectors`, `/{index}/{id}/_termvectors` and `/{index}/_mtermvectors`, since indexes no longer contain types, these typed endpoints are obsolete.. \ No newline at end of file +The `/{index}/{type}/_termvectors`, `/{index}/{type}/{id}/_termvectors` and `/{index}/{type}/_mtermvectors` REST endpoints have been removed in favour of `/{index}/_termvectors`, `/{index}/{id}/_termvectors` and `/{index}/_mtermvectors`, since indexes no longer contain types, these typed endpoints are obsolete.. + +[float] +==== Removal of queries + +The `common` query was deprecated in 7.x and has been removed in 8.0. +The same functionality can be achieved by the `match` query if the total number of hits is not tracked. + +[float] +===== Removal of query parameters + +The `cutoff_frequency` parameter was deprecated in 7.x and has been removed in 8.0 from `match` and `multi_match` queries. +The same functionality can be achieved without any configuration provided that the total number of hits is not tracked. diff --git a/docs/reference/query-dsl/common-terms-query.asciidoc b/docs/reference/query-dsl/common-terms-query.asciidoc deleted file mode 100644 index f2d784eb0c4c9..0000000000000 --- a/docs/reference/query-dsl/common-terms-query.asciidoc +++ /dev/null @@ -1,306 +0,0 @@ -[[query-dsl-common-terms-query]] -=== Common Terms Query - -deprecated[7.3.0,"Use <> instead, which skips blocks of documents efficiently, without any configuration, provided that the total number of hits is not tracked."] - -The `common` terms query is a modern alternative to stopwords which -improves the precision and recall of search results (by taking stopwords -into account), without sacrificing performance. - -[float] -==== The problem - -Every term in a query has a cost. A search for `"The brown fox"` -requires three term queries, one for each of `"the"`, `"brown"` and -`"fox"`, all of which are executed against all documents in the index. -The query for `"the"` is likely to match many documents and thus has a -much smaller impact on relevance than the other two terms. - -Previously, the solution to this problem was to ignore terms with high -frequency. By treating `"the"` as a _stopword_, we reduce the index size -and reduce the number of term queries that need to be executed. - -The problem with this approach is that, while stopwords have a small -impact on relevance, they are still important. If we remove stopwords, -we lose precision, (eg we are unable to distinguish between `"happy"` -and `"not happy"`) and we lose recall (eg text like `"The The"` or -`"To be or not to be"` would simply not exist in the index). - -[float] -==== The solution - -The `common` terms query divides the query terms into two groups: more -important (ie _low frequency_ terms) and less important (ie _high -frequency_ terms which would previously have been stopwords). - -First it searches for documents which match the more important terms. -These are the terms which appear in fewer documents and have a greater -impact on relevance. - -Then, it executes a second query for the less important terms -- terms -which appear frequently and have a low impact on relevance. But instead -of calculating the relevance score for *all* matching documents, it only -calculates the `_score` for documents already matched by the first -query. In this way the high frequency terms can improve the relevance -calculation without paying the cost of poor performance. - -If a query consists only of high frequency terms, then a single query is -executed as an `AND` (conjunction) query, in other words all terms are -required. Even though each individual term will match many documents, -the combination of terms narrows down the resultset to only the most -relevant. The single query can also be executed as an `OR` with a -specific -<>, -in this case a high enough value should probably be used. - -Terms are allocated to the high or low frequency groups based on the -`cutoff_frequency`, which can be specified as an absolute frequency -(`>=1`) or as a relative frequency (`0.0 .. 1.0`). (Remember that document -frequencies are computed on a per shard level as explained in the blog post -{defguide}/relevance-is-broken.html[Relevance is broken].) - -Perhaps the most interesting property of this query is that it adapts to -domain specific stopwords automatically. For example, on a video hosting -site, common terms like `"clip"` or `"video"` will automatically behave -as stopwords without the need to maintain a manual list. - -[float] -==== Examples - -In this example, words that have a document frequency greater than 0.1% -(eg `"this"` and `"is"`) will be treated as _common terms_. - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "common": { - "body": { - "query": "this is bonsai cool", - "cutoff_frequency": 0.001 - } - } - } -} --------------------------------------------------- -// CONSOLE -// TEST[warning:Deprecated field [common] used, replaced by [[match] query which can efficiently skip blocks of documents if the total number of hits is not tracked]] - -The number of terms which should match can be controlled with the -<> -(`high_freq`, `low_freq`), `low_freq_operator` (default `"or"`) and -`high_freq_operator` (default `"or"`) parameters. - -For low frequency terms, set the `low_freq_operator` to `"and"` to make -all terms required: - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "common": { - "body": { - "query": "nelly the elephant as a cartoon", - "cutoff_frequency": 0.001, - "low_freq_operator": "and" - } - } - } -} --------------------------------------------------- -// CONSOLE -// TEST[warning:Deprecated field [common] used, replaced by [[match] query which can efficiently skip blocks of documents if the total number of hits is not tracked]] - -which is roughly equivalent to: - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "bool": { - "must": [ - { "term": { "body": "nelly"}}, - { "term": { "body": "elephant"}}, - { "term": { "body": "cartoon"}} - ], - "should": [ - { "term": { "body": "the"}}, - { "term": { "body": "as"}}, - { "term": { "body": "a"}} - ] - } - } -} --------------------------------------------------- -// CONSOLE - -Alternatively use -<> -to specify a minimum number or percentage of low frequency terms which -must be present, for instance: - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "common": { - "body": { - "query": "nelly the elephant as a cartoon", - "cutoff_frequency": 0.001, - "minimum_should_match": 2 - } - } - } -} --------------------------------------------------- -// CONSOLE -// TEST[warning:Deprecated field [common] used, replaced by [[match] query which can efficiently skip blocks of documents if the total number of hits is not tracked]] - -which is roughly equivalent to: - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "bool": { - "must": { - "bool": { - "should": [ - { "term": { "body": "nelly"}}, - { "term": { "body": "elephant"}}, - { "term": { "body": "cartoon"}} - ], - "minimum_should_match": 2 - } - }, - "should": [ - { "term": { "body": "the"}}, - { "term": { "body": "as"}}, - { "term": { "body": "a"}} - ] - } - } -} --------------------------------------------------- -// CONSOLE - -A different -<> -can be applied for low and high frequency terms with the additional -`low_freq` and `high_freq` parameters. Here is an example when providing -additional parameters (note the change in structure): - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "common": { - "body": { - "query": "nelly the elephant not as a cartoon", - "cutoff_frequency": 0.001, - "minimum_should_match": { - "low_freq" : 2, - "high_freq" : 3 - } - } - } - } -} --------------------------------------------------- -// CONSOLE -// TEST[warning:Deprecated field [common] used, replaced by [[match] query which can efficiently skip blocks of documents if the total number of hits is not tracked]] - -which is roughly equivalent to: - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "bool": { - "must": { - "bool": { - "should": [ - { "term": { "body": "nelly"}}, - { "term": { "body": "elephant"}}, - { "term": { "body": "cartoon"}} - ], - "minimum_should_match": 2 - } - }, - "should": { - "bool": { - "should": [ - { "term": { "body": "the"}}, - { "term": { "body": "not"}}, - { "term": { "body": "as"}}, - { "term": { "body": "a"}} - ], - "minimum_should_match": 3 - } - } - } - } -} --------------------------------------------------- -// CONSOLE - -In this case it means the high frequency terms have only an impact on -relevance when there are at least three of them. But the most -interesting use of the -<> -for high frequency terms is when there are only high frequency terms: - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "common": { - "body": { - "query": "how not to be", - "cutoff_frequency": 0.001, - "minimum_should_match": { - "low_freq" : 2, - "high_freq" : 3 - } - } - } - } -} --------------------------------------------------- -// CONSOLE -// TEST[warning:Deprecated field [common] used, replaced by [[match] query which can efficiently skip blocks of documents if the total number of hits is not tracked]] - -which is roughly equivalent to: - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "bool": { - "should": [ - { "term": { "body": "how"}}, - { "term": { "body": "not"}}, - { "term": { "body": "to"}}, - { "term": { "body": "be"}} - ], - "minimum_should_match": "3<50%" - } - } -} --------------------------------------------------- -// CONSOLE - -The high frequency generated query is then slightly less restrictive -than with an `AND`. - -The `common` terms query also supports `boost` and `analyzer` as -parameters. diff --git a/docs/reference/query-dsl/full-text-queries.asciidoc b/docs/reference/query-dsl/full-text-queries.asciidoc index 0af99b61f194f..8fc53bc7e9b8a 100644 --- a/docs/reference/query-dsl/full-text-queries.asciidoc +++ b/docs/reference/query-dsl/full-text-queries.asciidoc @@ -29,10 +29,6 @@ The queries in this group are: The multi-field version of the `match` query. -<>:: - - A more specialized query which gives more preference to uncommon words. - <>:: Supports the compact Lucene <>, @@ -59,8 +55,6 @@ include::match-bool-prefix-query.asciidoc[] include::multi-match-query.asciidoc[] -include::common-terms-query.asciidoc[] - include::query-string-query.asciidoc[] include::simple-query-string-query.asciidoc[] diff --git a/docs/reference/query-dsl/match-query.asciidoc b/docs/reference/query-dsl/match-query.asciidoc index 14fc155cfccae..4b998d82cda24 100644 --- a/docs/reference/query-dsl/match-query.asciidoc +++ b/docs/reference/query-dsl/match-query.asciidoc @@ -119,53 +119,6 @@ GET /_search -------------------------------------------------- // CONSOLE -[[query-dsl-match-query-cutoff]] -===== Cutoff frequency - -deprecated[7.3.0,"This option can be omitted as the <> can skip block of documents efficiently, without any configuration, provided that the total number of hits is not tracked."] - -The match query supports a `cutoff_frequency` that allows -specifying an absolute or relative document frequency where high -frequency terms are moved into an optional subquery and are only scored -if one of the low frequency (below the cutoff) terms in the case of an -`or` operator or all of the low frequency terms in the case of an `and` -operator match. - -This query allows handling `stopwords` dynamically at runtime, is domain -independent and doesn't require a stopword file. It prevents scoring / -iterating high frequency terms and only takes the terms into account if a -more significant / lower frequency term matches a document. Yet, if all -of the query terms are above the given `cutoff_frequency` the query is -automatically transformed into a pure conjunction (`and`) query to -ensure fast execution. - -The `cutoff_frequency` can either be relative to the total number of -documents if in the range `[0..1)` or absolute if greater or equal to -`1.0`. - -Here is an example showing a query composed of stopwords exclusively: - -[source,js] --------------------------------------------------- -GET /_search -{ - "query": { - "match" : { - "message" : { - "query" : "to be or not to be", - "cutoff_frequency" : 0.001 - } - } - } -} --------------------------------------------------- -// CONSOLE -// TEST[warning:Deprecated field [cutoff_frequency] used, replaced by [you can omit this option, the [match] query can skip block of documents efficiently if the total number of hits is not tracked]] - -IMPORTANT: The `cutoff_frequency` option operates on a per-shard-level. This means -that when trying it out on test indexes with low document numbers you -should follow the advice in {defguide}/relevance-is-broken.html[Relevance is broken]. - [[query-dsl-match-query-synonyms]] ===== Synonyms diff --git a/docs/reference/query-dsl/multi-match-query.asciidoc b/docs/reference/query-dsl/multi-match-query.asciidoc index 9f574ed814d3c..8382b6ac6fbb4 100644 --- a/docs/reference/query-dsl/multi-match-query.asciidoc +++ b/docs/reference/query-dsl/multi-match-query.asciidoc @@ -151,8 +151,8 @@ follows: Also, accepts `analyzer`, `boost`, `operator`, `minimum_should_match`, `fuzziness`, `lenient`, `prefix_length`, `max_expansions`, `rewrite`, `zero_terms_query`, - `cutoff_frequency`, `auto_generate_synonyms_phrase_query` and `fuzzy_transpositions`, - as explained in <>. +`auto_generate_synonyms_phrase_query` and `fuzzy_transpositions`, +as explained in <>. [IMPORTANT] [[operator-min]] @@ -247,9 +247,7 @@ The score from each `match` clause is added together, then divided by the number of `match` clauses. Also, accepts `analyzer`, `boost`, `operator`, `minimum_should_match`, -`fuzziness`, `lenient`, `prefix_length`, `max_expansions`, `rewrite`, `zero_terms_query` -and `cutoff_frequency`, as explained in <>, but -*see <>*. +`fuzziness`, `lenient`, `prefix_length`, `max_expansions`, `rewrite`, and `zero_terms_query`. [[type-phrase]] ==== `phrase` and `phrase_prefix` @@ -389,8 +387,7 @@ explanation: +blended("smith", fields: [first_name, last_name]) Also, accepts `analyzer`, `boost`, `operator`, `minimum_should_match`, -`lenient`, `zero_terms_query` and `cutoff_frequency`, as explained in -<>. +`lenient` and `zero_terms_query`. [[cross-field-analysis]] ===== `cross_field` and analysis @@ -554,5 +551,4 @@ explained in <> are supported. The construct term queries, but do not have an effect on the prefix query constructed from the final term. -The `slop` and `cutoff_frequency` parameters are not supported by this query -type. +The `slop` parameter is not supported by this query type. diff --git a/docs/reference/sql/functions/search.asciidoc b/docs/reference/sql/functions/search.asciidoc index 6990f6669d69c..079571a4e37c6 100644 --- a/docs/reference/sql/functions/search.asciidoc +++ b/docs/reference/sql/functions/search.asciidoc @@ -58,17 +58,12 @@ additional configuration parameters (separated by semicolon `;`) for either `mat include-tagged::{sql-specs}/docs/docs.csv-spec[optionalParamsForMatch] ---- -In the more advanced example above, the `cutoff_frequency` parameter allows specifying an absolute or relative document frequency where -high frequency terms are moved into an optional subquery and are only scored if one of the low frequency (below the cutoff) terms in the -case of an `or` operator or all of the low frequency terms in the case of an `and` operator match. More about this you can find in the -<> page. - NOTE: The allowed optional parameters for a single-field `MATCH()` variant (for the `match` {es} query) are: `analyzer`, `auto_generate_synonyms_phrase_query`, -`cutoff_frequency`, `lenient`, `fuzziness`, `fuzzy_transpositions`, `fuzzy_rewrite`, `minimum_should_match`, `operator`, +`lenient`, `fuzziness`, `fuzzy_transpositions`, `fuzzy_rewrite`, `minimum_should_match`, `operator`, `max_expansions`, `prefix_length`. NOTE: The allowed optional parameters for a multi-field `MATCH()` variant (for the `multi_match` {es} query) are: `analyzer`, `auto_generate_synonyms_phrase_query`, -`cutoff_frequency`, `lenient`, `fuzziness`, `fuzzy_transpositions`, `fuzzy_rewrite`, `minimum_should_match`, `operator`, +`lenient`, `fuzziness`, `fuzzy_transpositions`, `fuzzy_rewrite`, `minimum_should_match`, `operator`, `max_expansions`, `prefix_length`, `slop`, `tie_breaker`, `type`. diff --git a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/50_queries_with_synonyms.yml b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/50_queries_with_synonyms.yml index ce9cc74955729..dca56565e6954 100644 --- a/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/50_queries_with_synonyms.yml +++ b/modules/analysis-common/src/test/resources/rest-api-spec/test/search.query/50_queries_with_synonyms.yml @@ -1,8 +1,5 @@ --- "Test common terms query with stacked tokens": - - skip: - features: "warnings" - - do: indices.create: index: test @@ -50,135 +47,6 @@ refresh: true - do: - warnings: - - 'Deprecated field [common] used, replaced by [[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 - body: - query: - common: - field1: - query: the fast brown - cutoff_frequency: 3 - low_freq_operator: or - - match: { hits.total: 3 } - - match: { hits.hits.0._id: "1" } - - match: { hits.hits.1._id: "2" } - - match: { hits.hits.2._id: "3" } - - - do: - warnings: - - 'Deprecated field [common] used, replaced by [[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 - body: - query: - common: - field1: - query: the fast brown - cutoff_frequency: 3 - low_freq_operator: and - - match: { hits.total: 2 } - - match: { hits.hits.0._id: "1" } - - match: { hits.hits.1._id: "2" } - - - do: - warnings: - - 'Deprecated field [common] used, replaced by [[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 - body: - query: - common: - field1: - query: the fast brown - cutoff_frequency: 3 - - match: { hits.total: 3 } - - match: { hits.hits.0._id: "1" } - - match: { hits.hits.1._id: "2" } - - match: { hits.hits.2._id: "3" } - - - do: - warnings: - - 'Deprecated field [common] used, replaced by [[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 - body: - query: - common: - field1: - query: the fast huge fox - minimum_should_match: - low_freq: 3 - - match: { hits.total: 1 } - - match: { hits.hits.0._id: "2" } - - - do: - warnings: - - 'Deprecated field [common] used, replaced by [[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 - body: - query: - common: - field1: - query: the fast lazy fox brown - cutoff_frequency: 1 - minimum_should_match: - high_freq: 5 - - match: { hits.total: 2 } - - match: { hits.hits.0._id: "2" } - - match: { hits.hits.1._id: "1" } - - - do: - warnings: - - 'Deprecated field [common] used, replaced by [[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 - body: - query: - common: - field1: - query: the fast lazy fox brown - cutoff_frequency: 1 - minimum_should_match: - high_freq: 6 - - match: { hits.total: 1 } - - match: { hits.hits.0._id: "2" } - - - do: - warnings: - - 'Deprecated field [common] used, replaced by [[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 - body: - query: - common: - field1: - query: the fast lazy fox brown - cutoff_frequency: 1 - - match: { hits.total: 1 } - - match: { hits.hits.0._id: "2" } - - - do: - warnings: - - 'Deprecated field [common] used, replaced by [[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 - body: - query: - common: - field1: - query: the quick brown - cutoff_frequency: 3 - - match: { hits.total: 3 } - - match: { hits.hits.0._id: "1" } - - match: { hits.hits.1._id: "2" } - - match: { hits.hits.2._id: "3" } - - - do: - warnings: - - 'Deprecated field [cutoff_frequency] used, replaced by [you can omit this option, 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 body: @@ -186,15 +54,12 @@ match: field1: query: the fast brown - cutoff_frequency: 3 operator: and - match: { hits.total: 2 } - match: { hits.hits.0._id: "1" } - match: { hits.hits.1._id: "2" } - do: - warnings: - - 'Deprecated field [cutoff_frequency] used, replaced by [you can omit this option, 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 body: @@ -202,7 +67,6 @@ match: field1: query: the fast brown - cutoff_frequency: 3 operator: or - match: { hits.total: 3 } - match: { hits.hits.0._id: "1" } @@ -210,8 +74,6 @@ - match: { hits.hits.2._id: "3" } - do: - warnings: - - 'Deprecated field [cutoff_frequency] used, replaced by [you can omit this option, 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 body: @@ -219,7 +81,6 @@ match: field1: query: the fast brown - cutoff_frequency: 3 minimum_should_match: 3 - match: { hits.total: 2 } - match: { hits.hits.0._id: "1" } @@ -227,7 +88,6 @@ - do: warnings: - - 'Deprecated field [cutoff_frequency] used, replaced by [you can omit this option, 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 body: @@ -235,7 +95,6 @@ multi_match: query: the fast brown fields: [ "field1", "field2" ] - cutoff_frequency: 3 operator: and - match: { hits.total: 3 } - match: { hits.hits.0._id: "3" } diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/QueryAnalyzer.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/QueryAnalyzer.java index c245e2cb3a20b..d3c4bdedde7d2 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/QueryAnalyzer.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/QueryAnalyzer.java @@ -22,7 +22,6 @@ import org.apache.lucene.index.PrefixCodedTerms; import org.apache.lucene.index.Term; import org.apache.lucene.queries.BlendedTermQuery; -import org.apache.lucene.queries.CommonTermsQuery; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; @@ -75,7 +74,6 @@ final class QueryAnalyzer { entry(BoostQuery.class, boostQuery()), entry(TermQuery.class, termQuery()), entry(TermInSetQuery.class, termInSetQuery()), - entry(CommonTermsQuery.class, commonTermsQuery()), entry(BlendedTermQuery.class, blendedTermQuery()), entry(PhraseQuery.class, phraseQuery()), entry(MultiPhraseQuery.class, multiPhraseQuery()), @@ -185,13 +183,6 @@ private static BiFunction synonymQuery() { }; } - private static BiFunction commonTermsQuery() { - return (query, version) -> { - Set terms = ((CommonTermsQuery) query).getTerms().stream().map(QueryExtraction::new).collect(toSet()); - return new Result(false, terms, Math.min(1, terms.size())); - }; - } - private static BiFunction blendedTermQuery() { return (query, version) -> { Set terms = ((BlendedTermQuery) query).getTerms().stream().map(QueryExtraction::new).collect(toSet()); diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/CandidateQueryTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/CandidateQueryTests.java index b191dd948c574..e487037afaea7 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/CandidateQueryTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/CandidateQueryTests.java @@ -46,7 +46,6 @@ import org.apache.lucene.index.TermsEnum; import org.apache.lucene.index.memory.MemoryIndex; import org.apache.lucene.queries.BlendedTermQuery; -import org.apache.lucene.queries.CommonTermsQuery; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.ConstantScoreQuery; @@ -84,8 +83,8 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.compress.CompressedXContent; -import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import org.elasticsearch.common.geo.ShapeRelation; +import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.IndexService; @@ -530,12 +529,6 @@ public void testDuelIdBased() throws Exception { public void testDuelSpecificQueries() throws Exception { List documents = new ArrayList<>(); - CommonTermsQuery commonTermsQuery = new CommonTermsQuery(Occur.SHOULD, Occur.SHOULD, 128); - commonTermsQuery.add(new Term("field", "quick")); - commonTermsQuery.add(new Term("field", "brown")); - commonTermsQuery.add(new Term("field", "fox")); - addQuery(commonTermsQuery, documents); - BlendedTermQuery blendedTermQuery = BlendedTermQuery.dismaxBlendedQuery(new Term[]{new Term("field", "quick"), new Term("field", "brown"), new Term("field", "fox")}, 1.0f); addQuery(blendedTermQuery, documents); diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java index ee31a81ae168a..57a6ca15ac593 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java @@ -44,7 +44,6 @@ import static org.elasticsearch.common.xcontent.XContentFactory.smileBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.yamlBuilder; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; -import static org.elasticsearch.index.query.QueryBuilders.commonTermsQuery; import static org.elasticsearch.index.query.QueryBuilders.geoBoundingBoxQuery; import static org.elasticsearch.index.query.QueryBuilders.geoDistanceQuery; import static org.elasticsearch.index.query.QueryBuilders.geoPolygonQuery; @@ -356,13 +355,10 @@ public void testPercolatorSpecificQueries() throws Exception { ); client().prepareIndex("test", "type", "1") - .setSource(jsonBuilder().startObject().field("query", commonTermsQuery("field1", "quick brown fox")).endObject()) - .get(); - client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("query", multiMatchQuery("quick brown fox", "field1", "field2") .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)).endObject()) .get(); - client().prepareIndex("test", "type", "3") + client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("query", spanNearQuery(spanTermQuery("field1", "quick"), 0) .addClause(spanTermQuery("field1", "brown")) @@ -372,7 +368,7 @@ public void testPercolatorSpecificQueries() throws Exception { .get(); client().admin().indices().prepareRefresh().get(); - client().prepareIndex("test", "type", "4") + client().prepareIndex("test", "type", "3") .setSource(jsonBuilder().startObject().field("query", spanNotQuery( spanNearQuery(spanTermQuery("field1", "quick"), 0) @@ -387,7 +383,7 @@ public void testPercolatorSpecificQueries() throws Exception { .get(); // doesn't match - client().prepareIndex("test", "type", "5") + client().prepareIndex("test", "type", "4") .setSource(jsonBuilder().startObject().field("query", spanNotQuery( spanNearQuery(spanTermQuery("field1", "quick"), 0) @@ -410,15 +406,13 @@ public void testPercolatorSpecificQueries() throws Exception { .setQuery(new PercolateQueryBuilder("query", source, XContentType.JSON)) .addSort("_id", SortOrder.ASC) .get(); - assertHitCount(response, 4); + assertHitCount(response, 3); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); assertThat(response.getHits().getAt(0).getScore(), equalTo(Float.NaN)); assertThat(response.getHits().getAt(1).getId(), equalTo("2")); assertThat(response.getHits().getAt(1).getScore(), equalTo(Float.NaN)); assertThat(response.getHits().getAt(2).getId(), equalTo("3")); assertThat(response.getHits().getAt(2).getScore(), equalTo(Float.NaN)); - assertThat(response.getHits().getAt(3).getId(), equalTo("4")); - assertThat(response.getHits().getAt(3).getScore(), equalTo(Float.NaN)); } public void testPercolatorQueryWithHighlighting() throws Exception { diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryAnalyzerTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryAnalyzerTests.java index c07467187f05f..358e9176e19b5 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryAnalyzerTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/QueryAnalyzerTests.java @@ -28,8 +28,8 @@ import org.apache.lucene.document.SortedNumericDocValuesField; import org.apache.lucene.index.Term; import org.apache.lucene.queries.BlendedTermQuery; -import org.apache.lucene.queries.CommonTermsQuery; import org.apache.lucene.search.BooleanClause; +import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.ConstantScoreQuery; @@ -44,7 +44,6 @@ import org.apache.lucene.search.TermInSetQuery; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermRangeQuery; -import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.join.QueryBitSetProducer; import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.search.spans.SpanFirstQuery; @@ -520,27 +519,10 @@ public void testExtractQueryMetadata_boostQuery() { assertThat(terms.get(0).bytes(), equalTo(termQuery1.getTerm().bytes())); } - public void testExtractQueryMetadata_commonTermsQuery() { - CommonTermsQuery commonTermsQuery = new CommonTermsQuery(BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD, 100); - commonTermsQuery.add(new Term("_field", "_term1")); - commonTermsQuery.add(new Term("_field", "_term2")); - Result result = analyze(commonTermsQuery, Version.CURRENT); - assertThat(result.verified, is(false)); - assertThat(result.minimumShouldMatch, equalTo(1)); - List terms = new ArrayList<>(result.extractions); - terms.sort(Comparator.comparing(qt -> qt.term)); - assertThat(terms.size(), equalTo(2)); - assertThat(result.minimumShouldMatch, equalTo(1)); - assertThat(terms.get(0).field(), equalTo("_field")); - assertThat(terms.get(0).text(), equalTo("_term1")); - assertThat(terms.get(1).field(), equalTo("_field")); - assertThat(terms.get(1).text(), equalTo("_term2")); - } - public void testExtractQueryMetadata_blendedTermQuery() { Term[] termsArr = new Term[]{new Term("_field", "_term1"), new Term("_field", "_term2")}; - BlendedTermQuery commonTermsQuery = BlendedTermQuery.dismaxBlendedQuery(termsArr, 1.0f); - Result result = analyze(commonTermsQuery, Version.CURRENT); + BlendedTermQuery blendedTermQuery = BlendedTermQuery.dismaxBlendedQuery(termsArr, 1.0f); + Result result = analyze(blendedTermQuery, Version.CURRENT); assertThat(result.verified, is(true)); assertThat(result.minimumShouldMatch, equalTo(1)); List terms = new ArrayList<>(result.extractions); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/310_match_bool_prefix.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/310_match_bool_prefix.yml index aa6a5158b4795..f92b0ffda80e3 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/310_match_bool_prefix.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/310_match_bool_prefix.yml @@ -345,19 +345,3 @@ setup: type: bool_prefix fields: [ "my_field1", "my_field2" ] slop: 1 - ---- -"multi_match multiple fields with cutoff_frequency throws exception": - - - do: - catch: /\[cutoff_frequency\] not allowed for type \[bool_prefix\]/ - 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 diff --git a/server/src/main/java/org/apache/lucene/queries/BlendedTermQuery.java b/server/src/main/java/org/apache/lucene/queries/BlendedTermQuery.java index f823f3a142690..5f00631ad6028 100644 --- a/server/src/main/java/org/apache/lucene/queries/BlendedTermQuery.java +++ b/server/src/main/java/org/apache/lucene/queries/BlendedTermQuery.java @@ -22,11 +22,8 @@ import org.apache.lucene.index.IndexReaderContext; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.Term; -import org.apache.lucene.index.TermStates; import org.apache.lucene.index.TermState; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.index.TermStates; import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.DisjunctionMaxQuery; import org.apache.lucene.search.Query; @@ -278,50 +275,6 @@ public int hashCode() { return Objects.hash(classHash(), Arrays.hashCode(equalsTerms())); } - /** - * @deprecated Since max_score optimization landed in 7.0, normal MultiMatchQuery - * will achieve the same result without any configuration. - */ - @Deprecated - public static BlendedTermQuery commonTermsBlendedQuery(Term[] terms, final float[] boosts, final float maxTermFrequency) { - return new BlendedTermQuery(terms, boosts) { - @Override - protected Query topLevelQuery(Term[] terms, TermStates[] ctx, int[] docFreqs, int maxDoc) { - BooleanQuery.Builder highBuilder = new BooleanQuery.Builder(); - BooleanQuery.Builder lowBuilder = new BooleanQuery.Builder(); - for (int i = 0; i < terms.length; i++) { - Query query = new TermQuery(terms[i], ctx[i]); - if (boosts != null && boosts[i] != 1f) { - query = new BoostQuery(query, boosts[i]); - } - if ((maxTermFrequency >= 1f && docFreqs[i] > maxTermFrequency) - || (docFreqs[i] > (int) Math.ceil(maxTermFrequency - * maxDoc))) { - highBuilder.add(query, BooleanClause.Occur.SHOULD); - } else { - lowBuilder.add(query, BooleanClause.Occur.SHOULD); - } - } - BooleanQuery high = highBuilder.build(); - BooleanQuery low = lowBuilder.build(); - if (low.clauses().isEmpty()) { - BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder(); - for (BooleanClause booleanClause : high) { - queryBuilder.add(booleanClause.getQuery(), Occur.MUST); - } - return queryBuilder.build(); - } else if (high.clauses().isEmpty()) { - return low; - } else { - return new BooleanQuery.Builder() - .add(high, BooleanClause.Occur.SHOULD) - .add(low, BooleanClause.Occur.MUST) - .build(); - } - } - }; - } - public static BlendedTermQuery dismaxBlendedQuery(Term[] terms, final float tieBreakerMultiplier) { return dismaxBlendedQuery(terms, null, tieBreakerMultiplier); } diff --git a/server/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java b/server/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java deleted file mode 100644 index 2d70ed8b90a05..0000000000000 --- a/server/src/main/java/org/apache/lucene/queries/ExtendedCommonTermsQuery.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.lucene.queries; - -import org.apache.lucene.search.BooleanClause.Occur; -import org.elasticsearch.common.lucene.search.Queries; - -/** - * Extended version of {@link CommonTermsQuery} that allows to pass in a - * {@code minimumNumberShouldMatch} specification that uses the actual num of high frequent terms - * to calculate the minimum matching terms. - * - * @deprecated Since max_optimization optimization landed in 7.0, normal MatchQuery - * will achieve the same result without any configuration. - */ -@Deprecated -public class ExtendedCommonTermsQuery extends CommonTermsQuery { - - public ExtendedCommonTermsQuery(Occur highFreqOccur, Occur lowFreqOccur, float maxTermFrequency) { - super(highFreqOccur, lowFreqOccur, maxTermFrequency); - } - - private String lowFreqMinNumShouldMatchSpec; - private String highFreqMinNumShouldMatchSpec; - - @Override - protected int calcLowFreqMinimumNumberShouldMatch(int numOptional) { - return calcMinimumNumberShouldMatch(lowFreqMinNumShouldMatchSpec, numOptional); - } - - protected int calcMinimumNumberShouldMatch(String spec, int numOptional) { - if (spec == null) { - return 0; - } - return Queries.calculateMinShouldMatch(numOptional, spec); - } - - @Override - protected int calcHighFreqMinimumNumberShouldMatch(int numOptional) { - return calcMinimumNumberShouldMatch(highFreqMinNumShouldMatchSpec, numOptional); - } - - public void setHighFreqMinimumNumberShouldMatch(String spec) { - this.highFreqMinNumShouldMatchSpec = spec; - } - - public String getHighFreqMinimumNumberShouldMatchSpec() { - return highFreqMinNumShouldMatchSpec; - } - - public void setLowFreqMinimumNumberShouldMatch(String spec) { - this.lowFreqMinNumShouldMatchSpec = spec; - } - - public String getLowFreqMinimumNumberShouldMatchSpec() { - return lowFreqMinNumShouldMatchSpec; - } - - public float getMaxTermFrequency() { - return this.maxTermFrequency; - } - -} diff --git a/server/src/main/java/org/elasticsearch/common/lucene/search/Queries.java b/server/src/main/java/org/elasticsearch/common/lucene/search/Queries.java index 96a0cafc35b11..2e004dfad2e55 100644 --- a/server/src/main/java/org/elasticsearch/common/lucene/search/Queries.java +++ b/server/src/main/java/org/elasticsearch/common/lucene/search/Queries.java @@ -20,7 +20,6 @@ package org.elasticsearch.common.lucene.search; import org.apache.lucene.index.Term; -import org.apache.lucene.queries.ExtendedCommonTermsQuery; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; @@ -148,8 +147,6 @@ public static Query applyMinimumShouldMatch(BooleanQuery query, @Nullable String public static Query maybeApplyMinimumShouldMatch(Query query, @Nullable String minimumShouldMatch) { if (query instanceof BooleanQuery) { return applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch); - } else if (query instanceof ExtendedCommonTermsQuery) { - ((ExtendedCommonTermsQuery)query).setLowFreqMinimumNumberShouldMatch(minimumShouldMatch); } return query; } diff --git a/server/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java deleted file mode 100644 index 5b2853ac359c2..0000000000000 --- a/server/src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.query; - -import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; -import org.apache.lucene.index.Term; -import org.apache.lucene.queries.ExtendedCommonTermsQuery; -import org.apache.lucene.search.BooleanClause.Occur; -import org.apache.lucene.search.Query; -import org.apache.lucene.util.BytesRefBuilder; -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParsingException; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.mapper.MappedFieldType; - -import java.io.IOException; -import java.util.Objects; - -/** - * CommonTermsQuery query is a query that executes high-frequency terms in a - * optional sub-query to prevent slow queries due to "common" terms like - * stopwords. This query basically builds 2 queries off the {@code #add(Term) - * added} terms where low-frequency terms are added to a required boolean clause - * and high-frequency terms are added to an optional boolean clause. The - * optional clause is only executed if the required "low-frequency' clause - * matches. - * - * @deprecated Since max_optimization optimization landed in 7.0, normal MatchQuery - * will achieve the same result without any configuration. - */ -@Deprecated -public class CommonTermsQueryBuilder extends AbstractQueryBuilder { - - public static final String COMMON_TERMS_QUERY_DEPRECATION_MSG = "[match] query which can efficiently " + - "skip blocks of documents if the total number of hits is not tracked"; - - public static final String NAME = "common"; - - public static final float DEFAULT_CUTOFF_FREQ = 0.01f; - public static final Operator DEFAULT_HIGH_FREQ_OCCUR = Operator.OR; - public static final Operator DEFAULT_LOW_FREQ_OCCUR = Operator.OR; - - private static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency"); - private static final ParseField MINIMUM_SHOULD_MATCH_FIELD = new ParseField("minimum_should_match"); - private static final ParseField LOW_FREQ_OPERATOR_FIELD = new ParseField("low_freq_operator"); - private static final ParseField HIGH_FREQ_OPERATOR_FIELD = new ParseField("high_freq_operator"); - private static final ParseField DISABLE_COORD_FIELD = new ParseField("disable_coord") - .withAllDeprecated("disable_coord has been removed"); - private static final ParseField ANALYZER_FIELD = new ParseField("analyzer"); - private static final ParseField QUERY_FIELD = new ParseField("query"); - private static final ParseField HIGH_FREQ_FIELD = new ParseField("high_freq"); - private static final ParseField LOW_FREQ_FIELD = new ParseField("low_freq"); - - private final String fieldName; - - private final Object text; - - private Operator highFreqOperator = DEFAULT_HIGH_FREQ_OCCUR; - - private Operator lowFreqOperator = DEFAULT_LOW_FREQ_OCCUR; - - private String analyzer = null; - - private String lowFreqMinimumShouldMatch = null; - - private String highFreqMinimumShouldMatch = null; - - private float cutoffFrequency = DEFAULT_CUTOFF_FREQ; - - /** - * Constructs a new common terms query. - * @deprecated See {@link CommonTermsQueryBuilder} for more details. - */ - @Deprecated - public CommonTermsQueryBuilder(String fieldName, Object text) { - if (Strings.isEmpty(fieldName)) { - throw new IllegalArgumentException("field name is null or empty"); - } - if (text == null) { - throw new IllegalArgumentException("text cannot be null"); - } - this.fieldName = fieldName; - this.text = text; - } - - /** - * Read from a stream. - * @deprecated See {@link CommonTermsQueryBuilder} for more details. - */ - @Deprecated - public CommonTermsQueryBuilder(StreamInput in) throws IOException { - super(in); - fieldName = in.readString(); - text = in.readGenericValue(); - highFreqOperator = Operator.readFromStream(in); - lowFreqOperator = Operator.readFromStream(in); - analyzer = in.readOptionalString(); - lowFreqMinimumShouldMatch = in.readOptionalString(); - highFreqMinimumShouldMatch = in.readOptionalString(); - cutoffFrequency = in.readFloat(); - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeString(this.fieldName); - out.writeGenericValue(this.text); - highFreqOperator.writeTo(out); - lowFreqOperator.writeTo(out); - out.writeOptionalString(analyzer); - out.writeOptionalString(lowFreqMinimumShouldMatch); - out.writeOptionalString(highFreqMinimumShouldMatch); - out.writeFloat(cutoffFrequency); - } - - public String fieldName() { - return this.fieldName; - } - - public Object value() { - return this.text; - } - - /** - * Sets the operator to use for terms with a high document frequency - * (greater than or equal to {@link #cutoffFrequency(float)}. Defaults to - * {@code AND}. - */ - public CommonTermsQueryBuilder highFreqOperator(Operator operator) { - this.highFreqOperator = (operator == null) ? DEFAULT_HIGH_FREQ_OCCUR : operator; - return this; - } - - public Operator highFreqOperator() { - return highFreqOperator; - } - - /** - * Sets the operator to use for terms with a low document frequency (less - * than {@link #cutoffFrequency(float)}. Defaults to {@code AND}. - */ - public CommonTermsQueryBuilder lowFreqOperator(Operator operator) { - this.lowFreqOperator = (operator == null) ? DEFAULT_LOW_FREQ_OCCUR : operator; - return this; - } - - public Operator lowFreqOperator() { - return lowFreqOperator; - } - - /** - * Explicitly set the analyzer to use. Defaults to use explicit mapping - * config for the field, or, if not set, the default search analyzer. - */ - public CommonTermsQueryBuilder analyzer(String analyzer) { - this.analyzer = analyzer; - return this; - } - - public String analyzer() { - return this.analyzer; - } - - /** - * Sets the cutoff document frequency for high / low frequent terms. A value - * in [0..1] (or absolute number >=1) representing the maximum threshold of - * a terms document frequency to be considered a low frequency term. - * Defaults to - * {@code {@value #DEFAULT_CUTOFF_FREQ}} - */ - public CommonTermsQueryBuilder cutoffFrequency(float cutoffFrequency) { - this.cutoffFrequency = cutoffFrequency; - return this; - } - - public float cutoffFrequency() { - return this.cutoffFrequency; - } - - /** - * Sets the minimum number of high frequent query terms that need to match in order to - * produce a hit when there are no low frequent terms. - */ - public CommonTermsQueryBuilder highFreqMinimumShouldMatch(String highFreqMinimumShouldMatch) { - this.highFreqMinimumShouldMatch = highFreqMinimumShouldMatch; - return this; - } - - public String highFreqMinimumShouldMatch() { - return this.highFreqMinimumShouldMatch; - } - - /** - * Sets the minimum number of low frequent query terms that need to match in order to - * produce a hit. - */ - public CommonTermsQueryBuilder lowFreqMinimumShouldMatch(String lowFreqMinimumShouldMatch) { - this.lowFreqMinimumShouldMatch = lowFreqMinimumShouldMatch; - return this; - } - - public String lowFreqMinimumShouldMatch() { - return this.lowFreqMinimumShouldMatch; - } - - @Override - protected void doXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(NAME); - builder.startObject(fieldName); - builder.field(QUERY_FIELD.getPreferredName(), text); - builder.field(HIGH_FREQ_OPERATOR_FIELD.getPreferredName(), highFreqOperator.toString()); - builder.field(LOW_FREQ_OPERATOR_FIELD.getPreferredName(), lowFreqOperator.toString()); - if (analyzer != null) { - builder.field(ANALYZER_FIELD.getPreferredName(), analyzer); - } - builder.field(CUTOFF_FREQUENCY_FIELD.getPreferredName(), cutoffFrequency); - if (lowFreqMinimumShouldMatch != null || highFreqMinimumShouldMatch != null) { - builder.startObject(MINIMUM_SHOULD_MATCH_FIELD.getPreferredName()); - if (lowFreqMinimumShouldMatch != null) { - builder.field(LOW_FREQ_FIELD.getPreferredName(), lowFreqMinimumShouldMatch); - } - if (highFreqMinimumShouldMatch != null) { - builder.field(HIGH_FREQ_FIELD.getPreferredName(), highFreqMinimumShouldMatch); - } - builder.endObject(); - } - printBoostAndQueryName(builder); - builder.endObject(); - builder.endObject(); - } - - public static CommonTermsQueryBuilder fromXContent(XContentParser parser) throws IOException { - String fieldName = null; - Object text = null; - float boost = AbstractQueryBuilder.DEFAULT_BOOST; - String analyzer = null; - String lowFreqMinimumShouldMatch = null; - String highFreqMinimumShouldMatch = null; - Operator highFreqOperator = CommonTermsQueryBuilder.DEFAULT_HIGH_FREQ_OCCUR; - Operator lowFreqOperator = CommonTermsQueryBuilder.DEFAULT_LOW_FREQ_OCCUR; - float cutoffFrequency = CommonTermsQueryBuilder.DEFAULT_CUTOFF_FREQ; - String queryName = null; - XContentParser.Token token; - String currentFieldName = null; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token == XContentParser.Token.START_OBJECT) { - throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, currentFieldName); - fieldName = currentFieldName; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token == XContentParser.Token.START_OBJECT) { - if (MINIMUM_SHOULD_MATCH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - String innerFieldName = null; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - innerFieldName = parser.currentName(); - } else if (token.isValue()) { - if (LOW_FREQ_FIELD.match(innerFieldName, parser.getDeprecationHandler())) { - lowFreqMinimumShouldMatch = parser.text(); - } else if (HIGH_FREQ_FIELD.match(innerFieldName, parser.getDeprecationHandler())) { - highFreqMinimumShouldMatch = parser.text(); - } else { - throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME + - "] query does not support [" + innerFieldName - + "] for [" + currentFieldName + "]"); - } - } else { - throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME + - "] unexpected token type [" + token - + "] after [" + innerFieldName + "]"); - } - } - } else { - throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME + - "] query does not support [" + currentFieldName + "]"); - } - } else if (token.isValue()) { - if (QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - text = parser.objectText(); - } else if (ANALYZER_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - analyzer = parser.text(); - } else if (DISABLE_COORD_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - // ignore - } else if (AbstractQueryBuilder.BOOST_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - boost = parser.floatValue(); - } else if (HIGH_FREQ_OPERATOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - highFreqOperator = Operator.fromString(parser.text()); - } else if (LOW_FREQ_OPERATOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - lowFreqOperator = Operator.fromString(parser.text()); - } else if (MINIMUM_SHOULD_MATCH_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - lowFreqMinimumShouldMatch = parser.text(); - } else if (CUTOFF_FREQUENCY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - cutoffFrequency = parser.floatValue(); - } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - queryName = parser.text(); - } else { - throw new ParsingException(parser.getTokenLocation(), "[" + CommonTermsQueryBuilder.NAME + - "] query does not support [" + currentFieldName + "]"); - } - } - } - } else { - throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName()); - fieldName = parser.currentName(); - text = parser.objectText(); - } - } - - return new CommonTermsQueryBuilder(fieldName, text) - .lowFreqMinimumShouldMatch(lowFreqMinimumShouldMatch) - .highFreqMinimumShouldMatch(highFreqMinimumShouldMatch) - .analyzer(analyzer) - .highFreqOperator(highFreqOperator) - .lowFreqOperator(lowFreqOperator) - .cutoffFrequency(cutoffFrequency) - .boost(boost) - .queryName(queryName); - } - - @Override - public String getWriteableName() { - return NAME; - } - - @Override - protected Query doToQuery(QueryShardContext context) throws IOException { - String field; - MappedFieldType fieldType = context.fieldMapper(fieldName); - if (fieldType != null) { - field = fieldType.name(); - } else { - field = fieldName; - } - - Analyzer analyzerObj; - if (analyzer == null) { - if (fieldType != null) { - analyzerObj = context.getSearchAnalyzer(fieldType); - } else { - analyzerObj = context.getMapperService().searchAnalyzer(); - } - } else { - analyzerObj = context.getMapperService().getIndexAnalyzers().get(analyzer); - if (analyzerObj == null) { - throw new QueryShardException(context, "[common] analyzer [" + analyzer + "] not found"); - } - } - - Occur highFreqOccur = highFreqOperator.toBooleanClauseOccur(); - Occur lowFreqOccur = lowFreqOperator.toBooleanClauseOccur(); - - ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, cutoffFrequency); - return parseQueryString(commonsQuery, text, field, analyzerObj, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch); - } - - private static Query parseQueryString(ExtendedCommonTermsQuery query, Object queryString, String field, Analyzer analyzer, - String lowFreqMinimumShouldMatch, String highFreqMinimumShouldMatch) throws IOException { - // Logic similar to QueryParser#getFieldQuery - try (TokenStream source = analyzer.tokenStream(field, queryString.toString())) { - source.reset(); - CharTermAttribute termAtt = source.addAttribute(CharTermAttribute.class); - BytesRefBuilder builder = new BytesRefBuilder(); - while (source.incrementToken()) { - // UTF-8 - builder.copyChars(termAtt); - query.add(new Term(field, builder.toBytesRef())); - } - } - - query.setLowFreqMinimumNumberShouldMatch(lowFreqMinimumShouldMatch); - query.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch); - return query; - } - - @Override - protected int doHashCode() { - return Objects.hash(fieldName, text, highFreqOperator, lowFreqOperator, analyzer, - lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch, cutoffFrequency); - } - - @Override - protected boolean doEquals(CommonTermsQueryBuilder other) { - return Objects.equals(fieldName, other.fieldName) && - Objects.equals(text, other.text) && - Objects.equals(highFreqOperator, other.highFreqOperator) && - Objects.equals(lowFreqOperator, other.lowFreqOperator) && - Objects.equals(analyzer, other.analyzer) && - Objects.equals(lowFreqMinimumShouldMatch, other.lowFreqMinimumShouldMatch) && - Objects.equals(highFreqMinimumShouldMatch, other.highFreqMinimumShouldMatch) && - Objects.equals(cutoffFrequency, other.cutoffFrequency); - } -} diff --git a/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java index fa93550759324..8d5b6e71927e2 100644 --- a/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/MatchQueryBuilder.java @@ -21,6 +21,7 @@ import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.Query; +import org.elasticsearch.Version; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; @@ -43,17 +44,7 @@ */ public class MatchQueryBuilder extends AbstractQueryBuilder { - private static final String CUTOFF_FREQUENCY_DEPRECATION_MSG = "you can omit this option, " + - "the [match] query can skip block of documents efficiently if the total number of hits is not tracked"; - public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query"); - /** - * @deprecated Since max_optimization optimization landed in 7.0, normal MatchQuery - * will achieve the same result without any configuration. - */ - @Deprecated - public static final ParseField CUTOFF_FREQUENCY_FIELD = - new ParseField("cutoff_frequency").withAllDeprecated(CUTOFF_FREQUENCY_DEPRECATION_MSG); public static final ParseField LENIENT_FIELD = new ParseField("lenient"); public static final ParseField FUZZY_TRANSPOSITIONS_FIELD = new ParseField("fuzzy_transpositions"); public static final ParseField FUZZY_REWRITE_FIELD = new ParseField("fuzzy_rewrite"); @@ -95,8 +86,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder { private MatchQuery.ZeroTermsQuery zeroTermsQuery = MatchQuery.DEFAULT_ZERO_TERMS_QUERY; - private Float cutoffFrequency = null; - private boolean autoGenerateSynonymsPhraseQuery = true; /** @@ -131,7 +120,10 @@ public MatchQueryBuilder(StreamInput in) throws IOException { minimumShouldMatch = in.readOptionalString(); fuzzyRewrite = in.readOptionalString(); fuzziness = in.readOptionalWriteable(Fuzziness::new); - cutoffFrequency = in.readOptionalFloat(); + // cutoff_frequency has been removed + if (in.getVersion().before(Version.V_8_0_0)) { + in.readOptionalFloat(); + } autoGenerateSynonymsPhraseQuery = in.readBoolean(); } @@ -150,7 +142,10 @@ protected void doWriteTo(StreamOutput out) throws IOException { out.writeOptionalString(minimumShouldMatch); out.writeOptionalString(fuzzyRewrite); out.writeOptionalWriteable(fuzziness); - out.writeOptionalFloat(cutoffFrequency); + // cutoff_frequency has been removed + if (out.getVersion().before(Version.V_8_0_0)) { + out.writeOptionalFloat(null); + } out.writeBoolean(autoGenerateSynonymsPhraseQuery); } @@ -241,24 +236,6 @@ public int maxExpansions() { return this.maxExpansions; } - /** - * Set a cutoff value in [0..1] (or absolute number >=1) representing the - * maximum threshold of a terms document frequency to be considered a low - * frequency term. - * - * @deprecated see {@link MatchQueryBuilder#CUTOFF_FREQUENCY_FIELD} for more details - */ - @Deprecated - public MatchQueryBuilder cutoffFrequency(float cutoff) { - this.cutoffFrequency = cutoff; - return this; - } - - /** Gets the optional cutoff value, can be {@code null} if not set previously */ - public Float cutoffFrequency() { - return this.cutoffFrequency; - } - /** Sets optional minimumShouldMatch value to apply to the query */ public MatchQueryBuilder minimumShouldMatch(String minimumShouldMatch) { this.minimumShouldMatch = minimumShouldMatch; @@ -375,9 +352,6 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio builder.field(FUZZY_TRANSPOSITIONS_FIELD.getPreferredName(), fuzzyTranspositions); builder.field(LENIENT_FIELD.getPreferredName(), lenient); builder.field(ZERO_TERMS_QUERY_FIELD.getPreferredName(), zeroTermsQuery.toString()); - if (cutoffFrequency != null) { - builder.field(CUTOFF_FREQUENCY_FIELD.getPreferredName(), cutoffFrequency); - } builder.field(GENERATE_SYNONYMS_PHRASE_QUERY.getPreferredName(), autoGenerateSynonymsPhraseQuery); printBoostAndQueryName(builder); builder.endObject(); @@ -402,7 +376,6 @@ protected Query doToQuery(QueryShardContext context) throws IOException { matchQuery.setTranspositions(fuzzyTranspositions); matchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(fuzzyRewrite, null, LoggingDeprecationHandler.INSTANCE)); matchQuery.setLenient(lenient); - matchQuery.setCommonTermsCutoff(cutoffFrequency); matchQuery.setZeroTermsQuery(zeroTermsQuery); matchQuery.setAutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery); @@ -424,7 +397,6 @@ protected boolean doEquals(MatchQueryBuilder other) { Objects.equals(lenient, other.lenient) && Objects.equals(fuzzyTranspositions, other.fuzzyTranspositions) && Objects.equals(zeroTermsQuery, other.zeroTermsQuery) && - Objects.equals(cutoffFrequency, other.cutoffFrequency) && Objects.equals(autoGenerateSynonymsPhraseQuery, other.autoGenerateSynonymsPhraseQuery); } @@ -432,7 +404,7 @@ protected boolean doEquals(MatchQueryBuilder other) { protected int doHashCode() { return Objects.hash(fieldName, value, operator, analyzer, fuzziness, prefixLength, maxExpansions, minimumShouldMatch, - fuzzyRewrite, lenient, fuzzyTranspositions, zeroTermsQuery, cutoffFrequency, autoGenerateSynonymsPhraseQuery); + fuzzyRewrite, lenient, fuzzyTranspositions, zeroTermsQuery, autoGenerateSynonymsPhraseQuery); } @Override @@ -453,7 +425,6 @@ public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOExc boolean fuzzyTranspositions = FuzzyQuery.defaultTranspositions; String fuzzyRewrite = null; boolean lenient = MatchQuery.DEFAULT_LENIENCY; - Float cutOffFrequency = null; ZeroTermsQuery zeroTermsQuery = MatchQuery.DEFAULT_ZERO_TERMS_QUERY; boolean autoGenerateSynonymsPhraseQuery = true; String queryName = null; @@ -491,8 +462,6 @@ public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOExc fuzzyTranspositions = parser.booleanValue(); } else if (LENIENT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { lenient = parser.booleanValue(); - } else if (CUTOFF_FREQUENCY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { - cutOffFrequency = parser.floatValue(); } else if (ZERO_TERMS_QUERY_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { String zeroTermsValue = parser.text(); if ("none".equalsIgnoreCase(zeroTermsValue)) { @@ -539,14 +508,10 @@ public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOExc matchQuery.fuzzyTranspositions(fuzzyTranspositions); matchQuery.maxExpansions(maxExpansion); matchQuery.lenient(lenient); - if (cutOffFrequency != null) { - matchQuery.cutoffFrequency(cutOffFrequency); - } matchQuery.zeroTermsQuery(zeroTermsQuery); matchQuery.autoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery); matchQuery.queryName(queryName); matchQuery.boost(boost); return matchQuery; } - } diff --git a/server/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java index fb400a9d3fc75..07f7ae4b79398 100644 --- a/server/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java @@ -22,6 +22,7 @@ import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.Query; import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.Version; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; @@ -51,9 +52,6 @@ */ public class MultiMatchQueryBuilder extends AbstractQueryBuilder { - private static final String CUTOFF_FREQUENCY_DEPRECATION_MSG = "you can omit this option, " + - "the [multi_match] query can skip block of documents efficiently if the total number of hits is not tracked"; - public static final String NAME = "multi_match"; public static final MultiMatchQueryBuilder.Type DEFAULT_TYPE = MultiMatchQueryBuilder.Type.BEST_FIELDS; @@ -67,8 +65,6 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder blendedFields) { - return blendTerms(context, new BytesRef[] {value}, commonTermsCutoff, tieBreaker, lenient, blendedFields); + return blendTerms(context, new BytesRef[] {value}, tieBreaker, lenient, blendedFields); } - static Query blendTerms(QueryShardContext context, BytesRef[] values, Float commonTermsCutoff, float tieBreaker, + static Query blendTerms(QueryShardContext context, BytesRef[] values, float tieBreaker, boolean lenient, List blendedFields) { List queries = new ArrayList<>(); @@ -276,11 +276,7 @@ static Query blendTerms(QueryShardContext context, BytesRef[] values, Float comm if (i > 0) { terms = Arrays.copyOf(terms, i); blendedBoost = Arrays.copyOf(blendedBoost, i); - if (commonTermsCutoff != null) { - queries.add(BlendedTermQuery.commonTermsBlendedQuery(terms, blendedBoost, commonTermsCutoff)); - } else { - queries.add(BlendedTermQuery.dismaxBlendedQuery(terms, blendedBoost, tieBreaker)); - } + queries.add(BlendedTermQuery.dismaxBlendedQuery(terms, blendedBoost, tieBreaker)); } if (queries.size() == 1) { return queries.get(0); diff --git a/server/src/main/java/org/elasticsearch/search/SearchModule.java b/server/src/main/java/org/elasticsearch/search/SearchModule.java index b0447d5781dfc..3e36def038e44 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/server/src/main/java/org/elasticsearch/search/SearchModule.java @@ -21,7 +21,6 @@ import org.apache.lucene.search.BooleanQuery; import org.elasticsearch.common.NamedRegistry; -import org.elasticsearch.common.ParseField; import org.elasticsearch.common.geo.GeoShapeType; import org.elasticsearch.common.geo.ShapesAvailability; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -34,7 +33,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoostingQueryBuilder; -import org.elasticsearch.index.query.CommonTermsQueryBuilder; import org.elasticsearch.index.query.ConstantScoreQueryBuilder; import org.elasticsearch.index.query.DisMaxQueryBuilder; import org.elasticsearch.index.query.DistanceFeatureQueryBuilder; @@ -272,7 +270,6 @@ import static java.util.Collections.unmodifiableMap; import static java.util.Objects.requireNonNull; -import static org.elasticsearch.index.query.CommonTermsQueryBuilder.COMMON_TERMS_QUERY_DEPRECATION_MSG; import static org.elasticsearch.index.query.SpanNearQueryBuilder.SpanGapQueryBuilder; /** @@ -769,8 +766,6 @@ private void registerQueryParsers(List plugins) { registerQuery(new QuerySpec<>(MoreLikeThisQueryBuilder.NAME, MoreLikeThisQueryBuilder::new, MoreLikeThisQueryBuilder::fromXContent)); registerQuery(new QuerySpec<>(WrapperQueryBuilder.NAME, WrapperQueryBuilder::new, WrapperQueryBuilder::fromXContent)); - registerQuery(new QuerySpec<>(new ParseField(CommonTermsQueryBuilder.NAME).withAllDeprecated(COMMON_TERMS_QUERY_DEPRECATION_MSG), - CommonTermsQueryBuilder::new, CommonTermsQueryBuilder::fromXContent)); registerQuery( new QuerySpec<>(SpanMultiTermQueryBuilder.NAME, SpanMultiTermQueryBuilder::new, SpanMultiTermQueryBuilder::fromXContent)); registerQuery(new QuerySpec<>(FunctionScoreQueryBuilder.NAME, FunctionScoreQueryBuilder::new, diff --git a/server/src/test/java/org/apache/lucene/search/uhighlight/CustomUnifiedHighlighterTests.java b/server/src/test/java/org/apache/lucene/search/uhighlight/CustomUnifiedHighlighterTests.java index 4e4b04d1ff19c..3c24dc2d42b82 100644 --- a/server/src/test/java/org/apache/lucene/search/uhighlight/CustomUnifiedHighlighterTests.java +++ b/server/src/test/java/org/apache/lucene/search/uhighlight/CustomUnifiedHighlighterTests.java @@ -30,7 +30,6 @@ import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.RandomIndexWriter; import org.apache.lucene.index.Term; -import org.apache.lucene.queries.CommonTermsQuery; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.IndexSearcher; @@ -147,21 +146,6 @@ public void testMultiPhrasePrefixQuery() throws Exception { BreakIterator.getSentenceInstance(Locale.ROOT), 0, outputs); } - public void testCommonTermsQuery() throws Exception { - final String[] inputs = { - "The quick brown fox." - }; - final String[] outputs = { - "The quick brown fox." - }; - CommonTermsQuery query = new CommonTermsQuery(BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD, 128); - query.add(new Term("text", "quick")); - query.add(new Term("text", "brown")); - query.add(new Term("text", "fox")); - assertHighlightOneDoc("text", inputs, new StandardAnalyzer(), query, Locale.ROOT, - BreakIterator.getSentenceInstance(Locale.ROOT), 0, outputs); - } - public void testSentenceBoundedBreakIterator() throws Exception { final String[] inputs = { "The quick brown fox in a long sentence with another quick brown fox. " + diff --git a/server/src/test/java/org/elasticsearch/index/query/CommonTermsQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/CommonTermsQueryBuilderTests.java deleted file mode 100644 index d02b60c52d531..0000000000000 --- a/server/src/test/java/org/elasticsearch/index/query/CommonTermsQueryBuilderTests.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.query; - -import org.apache.lucene.index.Term; -import org.apache.lucene.queries.ExtendedCommonTermsQuery; -import org.apache.lucene.search.Query; -import org.elasticsearch.common.ParsingException; -import org.elasticsearch.search.internal.SearchContext; -import org.elasticsearch.test.AbstractQueryTestCase; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.elasticsearch.index.query.QueryBuilders.commonTermsQuery; -import static org.elasticsearch.test.StreamsUtils.copyToStringFromClasspath; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.nullValue; - -public class CommonTermsQueryBuilderTests extends AbstractQueryTestCase { - - @Override - protected CommonTermsQueryBuilder doCreateTestQueryBuilder() { - int numberOfTerms = randomIntBetween(0, 10); - StringBuilder text = new StringBuilder(""); - for (int i = 0; i < numberOfTerms; i++) { - text.append(randomAlphaOfLengthBetween(1, 10)).append(" "); - } - - String fieldName = randomFrom(STRING_FIELD_NAME, - STRING_ALIAS_FIELD_NAME, - randomAlphaOfLengthBetween(1, 10)); - CommonTermsQueryBuilder query = new CommonTermsQueryBuilder(fieldName, text.toString()); - - if (randomBoolean()) { - query.cutoffFrequency(randomIntBetween(1, 10)); - } - - if (randomBoolean()) { - query.lowFreqOperator(randomFrom(Operator.values())); - } - - // number of low frequency terms that must match - if (randomBoolean()) { - query.lowFreqMinimumShouldMatch("" + randomIntBetween(1, 5)); - } - - if (randomBoolean()) { - query.highFreqOperator(randomFrom(Operator.values())); - } - - // number of high frequency terms that must match - if (randomBoolean()) { - query.highFreqMinimumShouldMatch("" + randomIntBetween(1, 5)); - } - - if (randomBoolean()) { - query.analyzer(randomAnalyzer()); - } - - return query; - } - - @Override - protected Map getAlternateVersions() { - Map alternateVersions = new HashMap<>(); - CommonTermsQueryBuilder commonTermsQuery = new CommonTermsQueryBuilder(randomAlphaOfLengthBetween(1, 10), - randomAlphaOfLengthBetween(1, 10)); - String contentString = "{\n" + - " \"common\" : {\n" + - " \"" + commonTermsQuery.fieldName() + "\" : \"" + commonTermsQuery.value() + "\"\n" + - " }\n" + - "}"; - alternateVersions.put(contentString, commonTermsQuery); - return alternateVersions; - } - - @Override - protected void doAssertLuceneQuery(CommonTermsQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException { - assertThat(query, instanceOf(ExtendedCommonTermsQuery.class)); - ExtendedCommonTermsQuery extendedCommonTermsQuery = (ExtendedCommonTermsQuery) query; - - List terms = extendedCommonTermsQuery.getTerms(); - if (!terms.isEmpty()) { - String expectedFieldName = expectedFieldName(queryBuilder.fieldName()); - String actualFieldName = terms.iterator().next().field(); - assertThat(actualFieldName, equalTo(expectedFieldName)); - } - - assertThat(extendedCommonTermsQuery.getHighFreqMinimumNumberShouldMatchSpec(), equalTo(queryBuilder.highFreqMinimumShouldMatch())); - assertThat(extendedCommonTermsQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo(queryBuilder.lowFreqMinimumShouldMatch())); - } - - @Override - public void testUnknownField() throws IOException { - super.testUnknownField(); - assertDeprecationWarning(); - } - - @Override - public void testUnknownObjectException() throws IOException { - super.testUnknownObjectException(); - assertDeprecationWarning(); - } - - @Override - public void testFromXContent() throws IOException { - super.testFromXContent(); - assertDeprecationWarning(); - } - - @Override - public void testValidOutput() throws IOException { - super.testValidOutput(); - assertDeprecationWarning(); - } - - public void testIllegalArguments() { - IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new CommonTermsQueryBuilder(null, "text")); - assertEquals("field name is null or empty", e.getMessage()); - e = expectThrows(IllegalArgumentException.class, () -> new CommonTermsQueryBuilder("", "text")); - assertEquals("field name is null or empty", e.getMessage()); - e = expectThrows(IllegalArgumentException.class, () -> new CommonTermsQueryBuilder("fieldName", null)); - assertEquals("text cannot be null", e.getMessage()); - } - - public void testFromJson() throws IOException { - String query = - "{\n" + - " \"common\" : {\n" + - " \"body\" : {\n" + - " \"query\" : \"nelly the elephant not as a cartoon\",\n" + - " \"high_freq_operator\" : \"AND\",\n" + - " \"low_freq_operator\" : \"OR\",\n" + - " \"cutoff_frequency\" : 0.001,\n" + - " \"minimum_should_match\" : {\n" + - " \"low_freq\" : \"2\",\n" + - " \"high_freq\" : \"3\"\n" + - " },\n" + - " \"boost\" : 42.0\n" + - " }\n" + - " }\n" + - "}"; - - CommonTermsQueryBuilder queryBuilder = (CommonTermsQueryBuilder) parseQuery(query); - checkGeneratedJson(query, queryBuilder); - - assertEquals(query, 42, queryBuilder.boost, 0.00001); - assertEquals(query, 0.001, queryBuilder.cutoffFrequency(), 0.0001); - assertEquals(query, Operator.OR, queryBuilder.lowFreqOperator()); - assertEquals(query, Operator.AND, queryBuilder.highFreqOperator()); - assertEquals(query, "nelly the elephant not as a cartoon", queryBuilder.value()); - - assertDeprecationWarning(); - } - - public void testCommonTermsQuery1() throws IOException { - String query = copyToStringFromClasspath("/org/elasticsearch/index/query/commonTerms-query1.json"); - Query parsedQuery = parseQuery(query).toQuery(createShardContext()); - assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class)); - ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery; - assertThat(ectQuery.getHighFreqMinimumNumberShouldMatchSpec(), nullValue()); - assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("2")); - - assertDeprecationWarning(); - } - - public void testCommonTermsQuery2() throws IOException { - String query = copyToStringFromClasspath("/org/elasticsearch/index/query/commonTerms-query2.json"); - Query parsedQuery = parseQuery(query).toQuery(createShardContext()); - assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class)); - ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery; - assertThat(ectQuery.getHighFreqMinimumNumberShouldMatchSpec(), equalTo("50%")); - assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("5<20%")); - - assertDeprecationWarning(); - } - - public void testCommonTermsQuery3() throws IOException { - String query = copyToStringFromClasspath("/org/elasticsearch/index/query/commonTerms-query3.json"); - Query parsedQuery = parseQuery(query).toQuery(createShardContext()); - assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class)); - ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery; - assertThat(ectQuery.getHighFreqMinimumNumberShouldMatchSpec(), nullValue()); - assertThat(ectQuery.getLowFreqMinimumNumberShouldMatchSpec(), equalTo("2")); - - assertDeprecationWarning(); - } - - // see #11730 - public void testCommonTermsQuery4() throws IOException { - Query parsedQuery = parseQuery(commonTermsQuery("field", "text")).toQuery(createShardContext()); - assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class)); - - assertDeprecationWarning(); - } - - public void testParseFailsWithMultipleFields() throws IOException { - String json = "{\n" + - " \"common\" : {\n" + - " \"message1\" : {\n" + - " \"query\" : \"nelly the elephant not as a cartoon\"\n" + - " },\n" + - " \"message2\" : {\n" + - " \"query\" : \"nelly the elephant not as a cartoon\"\n" + - " }\n" + - " }\n" + - "}"; - - ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json)); - assertEquals("[common] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage()); - - String shortJson = "{\n" + - " \"common\" : {\n" + - " \"message1\" : \"nelly the elephant not as a cartoon\",\n" + - " \"message2\" : \"nelly the elephant not as a cartoon\"\n" + - " }\n" + - "}"; - e = expectThrows(ParsingException.class, () -> parseQuery(shortJson)); - assertEquals("[common] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage()); - - assertDeprecationWarning(); - } - - private void assertDeprecationWarning() { - assertWarnings("Deprecated field [common] used, replaced by [" + CommonTermsQueryBuilder.COMMON_TERMS_QUERY_DEPRECATION_MSG + "]"); - } -} diff --git a/server/src/test/java/org/elasticsearch/index/query/CommonTermsQueryParserTests.java b/server/src/test/java/org/elasticsearch/index/query/CommonTermsQueryParserTests.java deleted file mode 100644 index f393683a10f7f..0000000000000 --- a/server/src/test/java/org/elasticsearch/index/query/CommonTermsQueryParserTests.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.index.query; - -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.test.ESSingleNodeTestCase; - -public class CommonTermsQueryParserTests extends ESSingleNodeTestCase { - public void testWhenParsedQueryIsNullNoNullPointerExceptionIsThrown() { - final String index = "test-index"; - final String type = "test-type"; - client() - .admin() - .indices() - .prepareCreate(index) - .addMapping(type, "name", "type=text,analyzer=stop") - .execute() - .actionGet(); - ensureGreen(); - - CommonTermsQueryBuilder commonTermsQueryBuilder = - new CommonTermsQueryBuilder("name", "the").queryName("query-name"); - - // the named query parses to null; we are testing this does not cause a NullPointerException - SearchResponse response = - client().prepareSearch(index).setQuery(commonTermsQueryBuilder).execute().actionGet(); - - assertNotNull(response); - assertEquals(response.getHits().getHits().length, 0); - } -} diff --git a/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java index f79bbb86242d9..76ea5aa9dc6a0 100644 --- a/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/MatchQueryBuilderTests.java @@ -23,7 +23,6 @@ import org.apache.lucene.analysis.CannedBinaryTokenStream; import org.apache.lucene.analysis.MockSynonymAnalyzer; import org.apache.lucene.index.Term; -import org.apache.lucene.queries.ExtendedCommonTermsQuery; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.FuzzyQuery; @@ -181,18 +180,6 @@ protected void doAssertLuceneQuery(MatchQueryBuilder queryBuilder, Query query, } } - if (query instanceof ExtendedCommonTermsQuery) { - assertTrue(queryBuilder.cutoffFrequency() != null); - ExtendedCommonTermsQuery ectq = (ExtendedCommonTermsQuery) query; - List terms = ectq.getTerms(); - if (!terms.isEmpty()) { - Term term = terms.iterator().next(); - String expectedFieldName = expectedFieldName(queryBuilder.fieldName()); - assertThat(term.field(), equalTo(expectedFieldName)); - } - assertEquals(queryBuilder.cutoffFrequency(), ectq.getMaxTermFrequency(), Float.MIN_VALUE); - } - if (query instanceof FuzzyQuery) { assertTrue(queryBuilder.fuzziness() != null); FuzzyQuery fuzzyQuery = (FuzzyQuery) query; diff --git a/server/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java b/server/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java index 970a4c3a37ecb..cd77a940a80a1 100644 --- a/server/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/index/query/MultiMatchQueryBuilderTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.query; import org.apache.lucene.index.Term; -import org.apache.lucene.queries.ExtendedCommonTermsQuery; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BoostQuery; @@ -171,7 +170,6 @@ protected void doAssertLuceneQuery(MultiMatchQueryBuilder queryBuilder, Query qu instanceOf(FuzzyQuery.class), instanceOf(MultiPhrasePrefixQuery.class), instanceOf(MatchAllDocsQuery.class), - instanceOf(ExtendedCommonTermsQuery.class), instanceOf(MatchNoDocsQuery.class), instanceOf(PhraseQuery.class), instanceOf(PointRangeQuery.class), diff --git a/server/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java b/server/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java index 58baadd83573d..30438c49998ab 100644 --- a/server/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java +++ b/server/src/test/java/org/elasticsearch/index/search/MultiMatchQueryTests.java @@ -129,7 +129,7 @@ public void testBlendTerms() { Query expected = BlendedTermQuery.dismaxBlendedQuery(terms, boosts, 1.0f); Query actual = MultiMatchQuery.blendTerm( indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }, null), - new BytesRef("baz"), null, 1f, false, Arrays.asList(new FieldAndBoost(ft1, 2), new FieldAndBoost(ft2, 3))); + new BytesRef("baz"), 1f, false, Arrays.asList(new FieldAndBoost(ft1, 2), new FieldAndBoost(ft2, 3))); assertEquals(expected, actual); } @@ -145,7 +145,7 @@ public void testBlendTermsWithFieldBoosts() { Query expected = BlendedTermQuery.dismaxBlendedQuery(terms, boosts, 1.0f); Query actual = MultiMatchQuery.blendTerm( indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }, null), - new BytesRef("baz"), null, 1f, false, Arrays.asList(new FieldAndBoost(ft1, 2), new FieldAndBoost(ft2, 3))); + new BytesRef("baz"), 1f, false, Arrays.asList(new FieldAndBoost(ft1, 2), new FieldAndBoost(ft2, 3))); assertEquals(expected, actual); } @@ -167,7 +167,7 @@ public Query termQuery(Object value, QueryShardContext context) { ), 1f); Query actual = MultiMatchQuery.blendTerm( indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }, null), - new BytesRef("baz"), null, 1f, true, Arrays.asList(new FieldAndBoost(ft1, 2), new FieldAndBoost(ft2, 3))); + new BytesRef("baz"), 1f, true, Arrays.asList(new FieldAndBoost(ft1, 2), new FieldAndBoost(ft2, 3))); assertEquals(expected, actual); } @@ -181,7 +181,7 @@ public Query termQuery(Object value, QueryShardContext context) { ft.setName("bar"); expectThrows(IllegalArgumentException.class, () -> MultiMatchQuery.blendTerm( indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }, null), - new BytesRef("baz"), null, 1f, false, Arrays.asList(new FieldAndBoost(ft, 1)))); + new BytesRef("baz"), 1f, false, Arrays.asList(new FieldAndBoost(ft, 1)))); } public void testBlendNoTermQuery() { @@ -205,7 +205,7 @@ public Query termQuery(Object value, QueryShardContext context) { ), 1.0f); Query actual = MultiMatchQuery.blendTerm( indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }, null), - new BytesRef("baz"), null, 1f, false, Arrays.asList(new FieldAndBoost(ft1, 2), new FieldAndBoost(ft2, 3))); + new BytesRef("baz"), 1f, false, Arrays.asList(new FieldAndBoost(ft1, 2), new FieldAndBoost(ft2, 3))); assertEquals(expected, actual); } diff --git a/server/src/test/java/org/elasticsearch/search/SearchModuleTests.java b/server/src/test/java/org/elasticsearch/search/SearchModuleTests.java index 2e019d1e2c432..512c80d5c0ef8 100644 --- a/server/src/test/java/org/elasticsearch/search/SearchModuleTests.java +++ b/server/src/test/java/org/elasticsearch/search/SearchModuleTests.java @@ -354,7 +354,7 @@ public List> getRescorers() { }; //add here deprecated queries to make sure we log a deprecation warnings when they are used - private static final String[] DEPRECATED_QUERIES = new String[] {"common"}; + private static final String[] DEPRECATED_QUERIES = new String[] {}; /** * Dummy test {@link AggregationBuilder} used to test registering aggregation builders. diff --git a/server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java b/server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java index f5e601fd97abd..855eb7286010c 100644 --- a/server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java +++ b/server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java @@ -19,7 +19,6 @@ package org.elasticsearch.search.fetch.subphase.highlight; import com.carrotsearch.randomizedtesting.generators.RandomPicks; - import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockTokenizer; @@ -81,7 +80,6 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.boostingQuery; -import static org.elasticsearch.index.query.QueryBuilders.commonTermsQuery; import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery; import static org.elasticsearch.index.query.QueryBuilders.existsQuery; import static org.elasticsearch.index.query.QueryBuilders.fuzzyQuery; @@ -1440,41 +1438,6 @@ public void testBoostingQueryTermVector() throws IOException { assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown fox jumps over the lazy dog")); } - public void testCommonTermsQuery() { - createIndex("test"); - ensureGreen(); - - client().prepareIndex("test", "type1") - .setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog") - .get(); - refresh(); - - logger.info("--> highlighting and searching on field1"); - SearchSourceBuilder source = searchSource() - .query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100)) - .highlighter(highlight().field("field2").order("score").preTags("").postTags("")); - - SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get(); - assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown fox jumps over the lazy dog")); - } - - public void testCommonTermsTermVector() throws IOException { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); - ensureGreen(); - - client().prepareIndex("test", "type1").setSource( - "field1", "this is a test", - "field2", "The quick brown fox jumps over the lazy dog").get(); - refresh(); - logger.info("--> highlighting and searching on field1"); - SearchSourceBuilder source = searchSource().query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100)) - .highlighter(highlight().field("field2").order("score").preTags("").postTags("")); - - SearchResponse searchResponse = client().prepareSearch("test").setSource(source).get(); - - assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown fox jumps over the lazy dog")); - } - public void testPlainHighlightDifferentFragmenter() throws Exception { assertAcked(prepareCreate("test") .addMapping("type1", "tags", "type=text")); @@ -2295,24 +2258,6 @@ public void testPostingsHighlighterBoostingQuery() throws IOException { equalTo("The quick brown fox jumps over the lazy dog! Second sentence.")); } - public void testPostingsHighlighterCommonTermsQuery() throws IOException { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); - ensureGreen(); - - client().prepareIndex("test", "type1") - .setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.").get(); - refresh(); - - logger.info("--> highlighting and searching on field1"); - SearchSourceBuilder source = searchSource().query(commonTermsQuery("field2", "quick brown").cutoffFrequency(100)) - .highlighter(highlight().field("field2").preTags("").postTags("")); - SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet(); - assertHitCount(searchResponse, 1L); - - assertHighlight(searchResponse, 0, "field2", 0, 1, - equalTo("The quick brown fox jumps over the lazy dog! Second sentence.")); - } - private static XContentBuilder type1PostingsffsetsMapping() throws IOException { return XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("properties") diff --git a/server/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java b/server/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java index 5fec898155487..415fa40ea9db8 100644 --- a/server/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java +++ b/server/src/test/java/org/elasticsearch/search/query/MultiMatchQueryIT.java @@ -19,7 +19,6 @@ package org.elasticsearch.search.query; import com.carrotsearch.randomizedtesting.generators.RandomPicks; - import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -72,8 +71,6 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.greaterThanOrEqualTo; -import static org.hamcrest.Matchers.lessThan; public class MultiMatchQueryIT extends ESIntegTestCase { @@ -303,66 +300,6 @@ public void testSingleField() throws NoSuchFieldException, IllegalAccessExceptio } - public void testCutoffFreq() throws ExecutionException, InterruptedException { - final long numDocs = client().prepareSearch("test").setSize(0) - .setQuery(matchAllQuery()).get().getHits().getTotalHits().value; - MatchQuery.Type type = MatchQuery.Type.BOOLEAN; - Float cutoffFrequency = randomBoolean() ? Math.min(1, numDocs * 1.f / between(10, 20)) : 1.f / between(10, 20); - SearchResponse searchResponse = client().prepareSearch("test") - .setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category") - .operator(Operator.OR).cutoffFrequency(cutoffFrequency))).get(); - Set topNIds = Sets.newHashSet("theone", "theother"); - for (int i = 0; i < searchResponse.getHits().getHits().length; i++) { - topNIds.remove(searchResponse.getHits().getAt(i).getId()); - // very likely that we hit a random doc that has the same score so orders are random since - // the doc id is the tie-breaker - } - assertThat(topNIds, empty()); - assertThat(searchResponse.getHits().getHits()[0].getScore(), - greaterThanOrEqualTo(searchResponse.getHits().getHits()[1].getScore())); - - cutoffFrequency = randomBoolean() ? Math.min(1, numDocs * 1.f / between(10, 20)) : 1.f / between(10, 20); - searchResponse = client().prepareSearch("test") - .setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category") - .operator(Operator.OR).cutoffFrequency(cutoffFrequency).type(type))).get(); - assertFirstHit(searchResponse, anyOf(hasId("theone"), hasId("theother"))); - assertThat(searchResponse.getHits().getHits()[0].getScore(), greaterThan(searchResponse.getHits().getHits()[1].getScore())); - long size = searchResponse.getHits().getTotalHits().value; - - searchResponse = client().prepareSearch("test") - .setQuery(randomizeType(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category") - .operator(Operator.OR).type(type))).get(); - assertFirstHit(searchResponse, anyOf(hasId("theone"), hasId("theother"))); - assertThat("common terms expected to be a way smaller result set", size, lessThan(searchResponse.getHits().getTotalHits().value)); - - cutoffFrequency = randomBoolean() ? Math.min(1, numDocs * 1.f / between(10, 20)) : 1.f / between(10, 20); - searchResponse = client().prepareSearch("test") - .setQuery(randomizeType(multiMatchQuery("marvel hero", "full_name", "first_name", "last_name", "category") - .operator(Operator.OR).cutoffFrequency(cutoffFrequency).type(type))).get(); - assertFirstHit(searchResponse, hasId("theother")); - - - searchResponse = client().prepareSearch("test") - .setQuery(randomizeType(multiMatchQuery("captain america", "full_name", "first_name", "last_name", "category") - .operator(Operator.AND).cutoffFrequency(cutoffFrequency).type(type))).get(); - assertHitCount(searchResponse, 1L); - assertFirstHit(searchResponse, hasId("theone")); - - searchResponse = client().prepareSearch("test") - .setQuery(randomizeType(multiMatchQuery("captain america", "full_name", "first_name", "last_name", "category") - .operator(Operator.AND).cutoffFrequency(cutoffFrequency).type(type))).get(); - assertHitCount(searchResponse, 1L); - assertFirstHit(searchResponse, hasId("theone")); - - searchResponse = client().prepareSearch("test") - .setQuery(randomizeType(multiMatchQuery("marvel hero", "first_name", "last_name", "category") - .operator(Operator.AND).cutoffFrequency(cutoffFrequency) - .analyzer("category") - .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS))).get(); - assertHitCount(searchResponse, 1L); - assertFirstHit(searchResponse, hasId("theother")); - } - public void testEquivalence() { final int numDocs = (int) client().prepareSearch("test").setSize(0) @@ -559,21 +496,11 @@ public void testCrossFieldMode() throws ExecutionException, InterruptedException .analyzer("category"))).get(); assertFirstHit(searchResponse, hasId("theone")); - searchResponse = client().prepareSearch("test") - .setQuery(randomizeType(multiMatchQuery("captain america marvel hero", "first_name", "last_name", "category") - .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS) - .cutoffFrequency(0.1f) - .analyzer("category") - .operator(Operator.OR))).get(); - assertFirstHit(searchResponse, anyOf(hasId("theother"), hasId("theone"))); - long numResults = searchResponse.getHits().getTotalHits().value; - searchResponse = client().prepareSearch("test") .setQuery(randomizeType(multiMatchQuery("captain america marvel hero", "first_name", "last_name", "category") .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS) .analyzer("category") .operator(Operator.OR))).get(); - assertThat(numResults, lessThan(searchResponse.getHits().getTotalHits().value)); assertFirstHit(searchResponse, hasId("theone")); diff --git a/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java b/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java index 2a7eb10313c51..afba40e2cb752 100644 --- a/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java +++ b/server/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java @@ -68,7 +68,6 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; -import static org.elasticsearch.index.query.QueryBuilders.commonTermsQuery; import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery; import static org.elasticsearch.index.query.QueryBuilders.existsQuery; import static org.elasticsearch.index.query.QueryBuilders.functionScoreQuery; @@ -101,7 +100,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHits; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSecondHit; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertThirdHit; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasScore; import static org.hamcrest.Matchers.closeTo; @@ -270,97 +268,6 @@ public void testAllDocsQueryString() throws InterruptedException, ExecutionExcep } } - public void testCommonTermsQuery() throws Exception { - - client().admin().indices().prepareCreate("test") - .addMapping("type1", "field1", "type=text,analyzer=whitespace") - .setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1)).get(); - indexRandom(true, client().prepareIndex("test", "type1", "3").setSource("field1", "quick lazy huge brown pidgin", "field2", - "the quick lazy huge brown fox jumps over the tree"), - client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox"), - client().prepareIndex("test", "type1", "2").setSource("field1", "the quick lazy huge brown fox jumps over the tree") ); - - - SearchResponse searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3) - .lowFreqOperator(Operator.OR)).get(); - assertHitCount(searchResponse, 3L); - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("2")); - assertThirdHit(searchResponse, hasId("3")); - - searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3) - .lowFreqOperator(Operator.AND)).get(); - assertThat(searchResponse.getHits().getTotalHits().value, equalTo(2L)); - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("2")); - - // Default - searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3)).get(); - assertHitCount(searchResponse, 3L); - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("2")); - assertThirdHit(searchResponse, hasId("3")); - - - searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the huge fox").lowFreqMinimumShouldMatch("2")).get(); - assertHitCount(searchResponse, 1L); - assertFirstHit(searchResponse, hasId("2")); - - searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1) - .highFreqMinimumShouldMatch("3")).get(); - assertHitCount(searchResponse, 2L); - assertFirstHit(searchResponse, hasId("2")); - assertSecondHit(searchResponse, hasId("1")); - - searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1) - .highFreqMinimumShouldMatch("4")).get(); - assertHitCount(searchResponse, 1L); - assertFirstHit(searchResponse, hasId("2")); - - // Default - searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the lazy fox brown").cutoffFrequency(1)).get(); - assertHitCount(searchResponse, 1L); - assertFirstHit(searchResponse, hasId("2")); - - searchResponse = client().prepareSearch().setQuery(commonTermsQuery("field1", "the quick brown").cutoffFrequency(3) - .analyzer("stop")).get(); - assertHitCount(searchResponse, 3L); - // stop drops "the" since its a stopword - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("3")); - assertThirdHit(searchResponse, hasId("2")); - - // try the same with match query - searchResponse = client().prepareSearch().setQuery(matchQuery("field1", "the quick brown").cutoffFrequency(3) - .operator(Operator.AND)).get(); - assertHitCount(searchResponse, 2L); - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("2")); - - searchResponse = client().prepareSearch().setQuery(matchQuery("field1", "the quick brown").cutoffFrequency(3) - .operator(Operator.OR)).get(); - assertHitCount(searchResponse, 3L); - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("2")); - assertThirdHit(searchResponse, hasId("3")); - - searchResponse = client().prepareSearch().setQuery(matchQuery("field1", "the quick brown").cutoffFrequency(3) - .operator(Operator.AND).analyzer("stop")).get(); - assertHitCount(searchResponse, 3L); - // stop drops "the" since its a stopword - assertFirstHit(searchResponse, hasId("1")); - assertSecondHit(searchResponse, hasId("3")); - assertThirdHit(searchResponse, hasId("2")); - - // try the same with multi match query - searchResponse = client().prepareSearch().setQuery(multiMatchQuery("the quick brown", "field1", "field2").cutoffFrequency(3) - .operator(Operator.AND)).get(); - assertHitCount(searchResponse, 3L); - assertFirstHit(searchResponse, hasId("3")); - assertSecondHit(searchResponse, hasId("1")); - assertThirdHit(searchResponse, hasId("2")); - } - public void testQueryStringAnalyzedWildcard() throws Exception { createIndex("test"); diff --git a/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java b/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java index 5f730ad138f96..7691b3346d72f 100644 --- a/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java +++ b/server/src/test/java/org/elasticsearch/validate/SimpleValidateQueryIT.java @@ -189,7 +189,7 @@ public void testExplainFilteredAlias() { assertThat(validateQueryResponse.getQueryExplanation().get(0).getExplanation(), containsString("field:value1")); } - public void testExplainWithRewriteValidateQuery() throws Exception { + public void testExplainWithRewriteValidateQuery() { client().admin().indices().prepareCreate("test") .addMapping("type1", "field", "type=text,analyzer=whitespace") .setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1)).get(); @@ -205,18 +205,6 @@ public void testExplainWithRewriteValidateQuery() throws Exception { assertExplanation(QueryBuilders.matchPhrasePrefixQuery("field", "ju"), containsString("field:jumps"), true); - // common terms queries - assertExplanation(QueryBuilders.commonTermsQuery("field", "huge brown pidgin").cutoffFrequency(1), - containsString("+field:pidgin field:huge field:brown"), true); - assertExplanation(QueryBuilders.commonTermsQuery("field", "the brown").analyzer("stop"), - containsString("field:brown"), true); - - // match queries with cutoff frequency - assertExplanation(QueryBuilders.matchQuery("field", "huge brown pidgin").cutoffFrequency(1), - containsString("+field:pidgin field:huge field:brown"), true); - assertExplanation(QueryBuilders.matchQuery("field", "the brown").analyzer("stop"), - containsString("field:brown"), true); - // fuzzy queries assertExplanation(QueryBuilders.fuzzyQuery("field", "the").fuzziness(Fuzziness.fromEdits(2)), containsString("field:the (field:tree)^0.3333333"), true); @@ -233,7 +221,7 @@ public void testExplainWithRewriteValidateQuery() throws Exception { containsString("field:huge field:pidgin"), true); } - public void testExplainWithRewriteValidateQueryAllShards() throws Exception { + public void testExplainWithRewriteValidateQueryAllShards() { client().admin().indices().prepareCreate("test") .addMapping("type1", "field", "type=text,analyzer=whitespace") .setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put("index.number_of_routing_shards", 2)).get(); @@ -262,7 +250,7 @@ public void testExplainWithRewriteValidateQueryAllShards() throws Exception { ), true, true); } - public void testIrrelevantPropertiesBeforeQuery() throws IOException { + public void testIrrelevantPropertiesBeforeQuery() { createIndex("test"); ensureGreen(); refresh(); @@ -271,7 +259,7 @@ public void testIrrelevantPropertiesBeforeQuery() throws IOException { new BytesArray("{\"foo\": \"bar\", \"query\": {\"term\" : { \"user\" : \"kimchy\" }}}"))).get().isValid(), equalTo(false)); } - public void testIrrelevantPropertiesAfterQuery() throws IOException { + public void testIrrelevantPropertiesAfterQuery() { createIndex("test"); ensureGreen(); refresh(); @@ -311,7 +299,7 @@ private static void assertExplanations(QueryBuilder queryBuilder, } } - public void testExplainTermsQueryWithLookup() throws Exception { + public void testExplainTermsQueryWithLookup() { client().admin().indices().prepareCreate("twitter") .addMapping("_doc", "user", "type=integer", "followers", "type=integer") .setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put("index.number_of_routing_shards", 2)).get(); diff --git a/server/src/test/resources/org/elasticsearch/index/query/commonTerms-query1.json b/server/src/test/resources/org/elasticsearch/index/query/commonTerms-query1.json deleted file mode 100644 index b2728dac09df4..0000000000000 --- a/server/src/test/resources/org/elasticsearch/index/query/commonTerms-query1.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "common" : { - "dogs" : { - "query" : "buck mia tom", - "cutoff_frequency" : 1, - "minimum_should_match" : { - "low_freq" : 2 - } - } - } -} diff --git a/server/src/test/resources/org/elasticsearch/index/query/commonTerms-query2.json b/server/src/test/resources/org/elasticsearch/index/query/commonTerms-query2.json deleted file mode 100644 index aeb281bb7592a..0000000000000 --- a/server/src/test/resources/org/elasticsearch/index/query/commonTerms-query2.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "common" : { - "dogs" : { - "query" : "buck mia tom", - "minimum_should_match" : { - "high_freq" : "50%", - "low_freq" : "5<20%" - } - } - } -} diff --git a/server/src/test/resources/org/elasticsearch/index/query/commonTerms-query3.json b/server/src/test/resources/org/elasticsearch/index/query/commonTerms-query3.json deleted file mode 100644 index f276209ffc7ed..0000000000000 --- a/server/src/test/resources/org/elasticsearch/index/query/commonTerms-query3.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "common" : { - "dogs" : { - "query" : "buck mia tom", - "cutoff_frequency" : 1, - "minimum_should_match" : 2 - } - } -} diff --git a/x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec b/x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec index 936c7eef88191..00f7632c9fc44 100644 --- a/x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec +++ b/x-pack/plugin/sql/qa/src/main/resources/docs/docs.csv-spec @@ -1001,12 +1001,13 @@ Frank Herbert |God Emperor of Dune|7.0029488 optionalParamsForMatch // tag::optionalParamsForMatch -SELECT author, name, SCORE() FROM library WHERE MATCH(name, 'to the star', 'operator=or;cutoff_frequency=0.2'); +SELECT author, name, SCORE() FROM library WHERE MATCH(name, 'to the star', 'operator=OR;fuzziness=AUTO:1,5;minimum_should_match=1') +ORDER BY SCORE() DESC LIMIT 2; author | name | SCORE() -----------------+------------------------------------+--------------- -Peter F. Hamilton|Pandora's Star |3.0997515 Douglas Adams |The Hitchhiker's Guide to the Galaxy|3.1756816 +Peter F. Hamilton|Pandora's Star |3.0997515 // end::optionalParamsForMatch ; diff --git a/x-pack/plugin/sql/qa/src/main/resources/fulltext.csv-spec b/x-pack/plugin/sql/qa/src/main/resources/fulltext.csv-spec index cb410080e77bd..6379f6bf26f1a 100644 --- a/x-pack/plugin/sql/qa/src/main/resources/fulltext.csv-spec +++ b/x-pack/plugin/sql/qa/src/main/resources/fulltext.csv-spec @@ -92,14 +92,14 @@ SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH(first_nam ; matchQueryWithOptions -SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH(first_name, 'Erez', 'lenient=true;cutoff_frequency=2;fuzzy_rewrite=scoring_boolean;minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true'); +SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH(first_name, 'Erez', 'lenient=true;fuzzy_rewrite=scoring_boolean;minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true'); emp_no:i | first_name:s | gender:s | last_name:s 10076 |Erez |F |Ritzmann ; matchQueryWithOptionsInMultipleCommaSeparatedStrings -SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH(first_name, 'Erez', 'lenient=true;cutoff_frequency=2','fuzzy_rewrite=scoring_boolean;minimum_should_match=1','operator=AND', 'max_expansions=30;prefix_length=1;analyzer=english;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true'); +SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH(first_name, 'Erez', 'lenient=true','fuzzy_rewrite=scoring_boolean;minimum_should_match=1','operator=AND', 'max_expansions=30;prefix_length=1;analyzer=english;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true'); emp_no:i | first_name:s | gender:s | last_name:s 10076 |Erez |F |Ritzmann @@ -113,14 +113,14 @@ SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_na ; multiMatchQueryAllOptions -SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_name,last_name', 'Morton', 'slop=1;lenient=true;cutoff_frequency=2;tie_breaker=0.1;fuzzy_rewrite=scoring_boolean;minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;type=best_fields;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true'); +SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_name,last_name', 'Morton', 'slop=1;lenient=true;tie_breaker=0.1;fuzzy_rewrite=scoring_boolean;minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;type=best_fields;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true'); emp_no:i | first_name:s | gender:s | last_name:s 10095 |Hilari |M |Morton ; multiMatchQueryWithInMultipleCommaSeparatedStrings -SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_name,last_name', 'Morton', 'slop=1;lenient=true', 'cutoff_frequency=2','tie_breaker=0.1;fuzzy_rewrite=scoring_boolean','minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;type=best_fields;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true'); +SELECT emp_no, first_name, gender, last_name FROM test_emp WHERE MATCH('first_name,last_name', 'Morton', 'slop=1;lenient=true', 'tie_breaker=0.1;fuzzy_rewrite=scoring_boolean','minimum_should_match=1;operator=AND;max_expansions=30;prefix_length=1;analyzer=english;type=best_fields;auto_generate_synonyms_phrase_query=true;fuzzy_transpositions=true'); emp_no:i | first_name:s | gender:s | last_name:s 10095 |Hilari |M |Morton diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQuery.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQuery.java index 58ca09da929f9..3fca7630bd5a6 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQuery.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MatchQuery.java @@ -32,7 +32,6 @@ public class MatchQuery extends LeafQuery { BUILDER_APPLIERS = Map.ofEntries( entry("analyzer", MatchQueryBuilder::analyzer), entry("auto_generate_synonyms_phrase_query", (qb, s) -> qb.autoGenerateSynonymsPhraseQuery(Booleans.parseBoolean(s))), - entry("cutoff_frequency", (qb, s) -> qb.cutoffFrequency(Float.valueOf(s))), entry("fuzziness", (qb, s) -> qb.fuzziness(Fuzziness.fromString(s))), entry("fuzzy_transpositions", (qb, s) -> qb.fuzzyTranspositions(Booleans.parseBoolean(s))), entry("fuzzy_rewrite", MatchQueryBuilder::fuzzyRewrite), diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQuery.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQuery.java index f51f8275a898c..ab6190ad6eee1 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQuery.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/querydsl/query/MultiMatchQuery.java @@ -32,7 +32,6 @@ public class MultiMatchQuery extends LeafQuery { // appliers.put("zero_terms_query", (qb, s) -> qb.zeroTermsQuery(s)); entry("analyzer", MultiMatchQueryBuilder::analyzer), entry("auto_generate_synonyms_phrase_query", (qb, s) -> qb.autoGenerateSynonymsPhraseQuery(Booleans.parseBoolean(s))), - entry("cutoff_frequency", (qb, s) -> qb.cutoffFrequency(Float.valueOf(s))), entry("fuzziness", (qb, s) -> qb.fuzziness(Fuzziness.fromString(s))), entry("fuzzy_rewrite", MultiMatchQueryBuilder::fuzzyRewrite), entry("fuzzy_transpositions", (qb, s) -> qb.fuzzyTranspositions(Booleans.parseBoolean(s))),