diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/340_doc_values_field.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/340_doc_values_field.yml index c23584102b212..8709a2cac001c 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/340_doc_values_field.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/340_doc_values_field.yml @@ -82,32 +82,6 @@ - match: { hits.total: 2 } - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - terms: { - some_keyword: ["400", "5"], - rewrite_override: "index_only" - } - - - match: { hits.total: 2 } - - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - terms: { - some_keyword: ["400", "5"], - rewrite_override: "doc_values_only" - } - - - match: { hits.total: 2 } - - do: search: rest_total_hits_as_int: true @@ -121,34 +95,6 @@ - match: { hits.total: 1 } - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - fuzzy: - some_keyword: { - value: "402", - rewrite_override: "index_only" - } - - - match: { hits.total: 1 } - - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - fuzzy: - some_keyword: { - value: "402", - rewrite_override: "doc_values_only" - } - - - match: { hits.total: 1 } - - do: search: rest_total_hits_as_int: true @@ -162,34 +108,6 @@ - match: { hits.total: 1 } - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - regexp: - some_keyword: { - value: "40*", - rewrite_override: "index_only" - } - - - match: { hits.total: 1 } - - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - regexp: - some_keyword: { - value: "40*", - rewrite_override: "doc_values_only" - } - - - match: { hits.total: 1 } - - do: search: rest_total_hits_as_int: true @@ -203,34 +121,6 @@ - match: { hits.total: 1 } - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - wildcard: - some_keyword: { - value: "ing*", - rewrite_override: "index_only" - } - - - match: { hits.total: 1 } - - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - wildcard: - some_keyword: { - value: "ing*", - rewrite_override: "doc_values_only" - } - - - match: { hits.total: 1 } - - do: search: rest_total_hits_as_int: true @@ -242,34 +132,6 @@ - match: { hits.hits.0._source.some_keyword: "ingesting some random keyword data" } - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - prefix: - some_keyword: { - value: "ing", - rewrite_override: "index_only" - } - - - match: { hits.hits.0._source.some_keyword: "ingesting some random keyword data" } - - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - prefix: - some_keyword: { - value: "ing", - rewrite_override: "doc_values_only" - } - - - match: { hits.hits.0._source.some_keyword: "ingesting some random keyword data" } - - do: search: rest_total_hits_as_int: true @@ -283,37 +145,6 @@ - match: { hits.total: 2 } - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - range: { - "some_keyword": { - "lt": 500, - rewrite_override: "index_only" - - } } - - - match: { hits.total: 2 } - - - do: - search: - rest_total_hits_as_int: true - index: test-iodvq - body: - query: - range: { - "some_keyword": { - "lt": 500, - rewrite_override: "doc_values_only" - - } } - - - match: { hits.total: 2 } - - - do: search: rest_total_hits_as_int: true @@ -2088,3 +1919,282 @@ } - match: { hits.total: 0 } + +--- +"search with rewrite_override": + - skip: + features: [ "headers" ] + version: " - 2.16.99" + reason: "rewrite_override parameter was added in 2.17.0" + - do: + indices.create: + index: test-rewrite + body: + mappings: + properties: + some_keyword: + type: keyword + index: true + doc_values: true + some_keyword_index: + type: keyword + index: true + doc_values: false + some_keyword_dv: + type: keyword + index: false + doc_values: true + + - do: + bulk: + index: test-rewrite + refresh: true + body: + - '{"index": {"_index": "test-rewrite", "_id": "1" }}' + - '{ "some_keyword": "ingesting some random keyword data", "some_keyword_index": "ingesting some random keyword data", "some_keyword_dv": "ingesting some random keyword data" }' + - '{ "index": { "_index": "test-rewrite", "_id": "2" }}' + - '{ "some_keyword": "400", "some_keyword_index": "400", "some_keyword_dv": "400" }' + - '{ "index": { "_index": "test-rewrite", "_id": "3" } }' + - '{ "some_keyword": "5", "some_keyword_index": "5", "some_keyword_dv": "5" }' + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + terms: + some_keyword: ["400", "5"] + + - match: { hits.total: 2 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + terms: { + some_keyword_index: ["400", "5"], + rewrite_override: "index_only" + } + + - match: { hits.total: 2 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + terms: { + some_keyword_dv: ["400", "5"], + rewrite_override: "doc_values_only" + } + + - match: { hits.total: 2 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + fuzzy: + some_keyword: { + value: "402" + } + + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + fuzzy: + some_keyword_index: { + value: "402", + rewrite_override: "index_only" + } + + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + fuzzy: + some_keyword_dv: { + value: "402", + rewrite_override: "doc_values_only" + } + + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + regexp: + some_keyword: { + value: "40*" + } + + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + regexp: + some_keyword_index: { + value: "40*", + rewrite_override: "index_only" + } + + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + regexp: + some_keyword_dv: { + value: "40*", + rewrite_override: "doc_values_only" + } + + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + wildcard: + some_keyword: { + value: "ing*" + } + + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + wildcard: + some_keyword_index: { + value: "ing*", + rewrite_override: "index_only" + } + + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + wildcard: + some_keyword_dv: { + value: "ing*", + rewrite_override: "doc_values_only" + } + + - match: { hits.total: 1 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + prefix: + some_keyword: "ing" + + - match: { hits.hits.0._source.some_keyword: "ingesting some random keyword data" } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + prefix: + some_keyword_index: { + value: "ing", + rewrite_override: "index_only" + } + + - match: { hits.hits.0._source.some_keyword: "ingesting some random keyword data" } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + prefix: + some_keyword_dv: { + value: "ing", + rewrite_override: "doc_values_only" + } + + - match: { hits.hits.0._source.some_keyword: "ingesting some random keyword data" } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + range: { + "some_keyword": { + "lt": 500 + } } + + - match: { hits.total: 2 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + range: { + "some_keyword_index": { + "lt": 500, + rewrite_override: "index_only" + + } } + + - match: { hits.total: 2 } + + - do: + search: + rest_total_hits_as_int: true + index: test-rewrite + body: + query: + range: { + "some_keyword_dv": { + "lt": 500, + rewrite_override: "doc_values_only" + + } } + + - match: { hits.total: 2 } diff --git a/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java index f2ff416c059f8..cadc1acbf60ef 100644 --- a/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/TermsQueryBuilder.java @@ -57,8 +57,8 @@ import org.opensearch.index.IndexSettings; import org.opensearch.index.mapper.ConstantFieldType; import org.opensearch.index.mapper.MappedFieldType; -import org.opensearch.index.query.support.QueryParsers; import org.opensearch.index.mapper.NumberFieldMapper; +import org.opensearch.index.query.support.QueryParsers; import org.opensearch.indices.TermsLookup; import java.io.IOException; @@ -250,7 +250,8 @@ private TermsQueryBuilder(String fieldName, Iterable values, String rewriteOv private TermsQueryBuilder(String fieldName, Supplier> supplier, String rewriteOverride) { this(fieldName, supplier); this.rewriteOverride = rewriteOverride; - + } + private TermsQueryBuilder(String fieldName, Supplier> supplier, ValueType valueType) { this(fieldName, supplier); this.valueType = valueType; @@ -497,7 +498,6 @@ public static TermsQueryBuilder fromXContent(XContentParser parser) throws IOExc queryName = parser.text(); } else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) { rewriteOverride = parser.textOrNull(); - } } else if (VALUE_TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { valueTypeStr = parser.text(); } else { @@ -535,7 +535,10 @@ public static TermsQueryBuilder fromXContent(XContentParser parser) throws IOExc } } - return new TermsQueryBuilder(fieldName, values, termsLookup).boost(boost).queryName(queryName).valueType(valueType).rewriteOverride(rewriteOverride); + return new TermsQueryBuilder(fieldName, values, termsLookup).boost(boost) + .queryName(queryName) + .valueType(valueType) + .rewriteOverride(rewriteOverride); } static List parseValues(XContentParser parser) throws IOException { @@ -644,7 +647,7 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) { supplier.set(list); return null; }))); - return new TermsQueryBuilder(this.fieldName, supplier::get, valueType, rewriteOverride); + return new TermsQueryBuilder(this.fieldName, supplier::get, valueType); } if (values == null || values.isEmpty()) {