diff --git a/server/src/main/java/org/opensearch/index/mapper/KeywordFieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/KeywordFieldMapper.java index d4020a3937208..01d33b7ddd9c2 100644 --- a/server/src/main/java/org/opensearch/index/mapper/KeywordFieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/KeywordFieldMapper.java @@ -388,7 +388,7 @@ protected BytesRef indexedValueForSearch(Object value) { } @Override - public Query termsQuery(List values, RewriteOverride rewriteOverride, QueryShardContext context) { + public Query termsQuery(List values, RewriteOverride rewriteOverride, QueryShardContext context) { failIfNotIndexedAndNoDocValues(); if (rewriteOverride == null) { rewriteOverride = RewriteOverride.DEFAULT; @@ -461,17 +461,15 @@ public Query prefixQuery( Query indexQuery = super.prefixQuery(value, method, caseInsensitive, context); Query dvQuery = super.prefixQuery(value, MultiTermQuery.DOC_VALUES_REWRITE, caseInsensitive, context); query = new IndexOrDocValuesQuery(indexQuery, dvQuery); - } - else if (hasDocValues()) { + } else if (hasDocValues()) { if (caseInsensitive) { return AutomatonQueries.caseInsensitivePrefixQuery( - (new Term(name(), indexedValueForSearch(value))), - MultiTermQuery.DOC_VALUES_REWRITE + (new Term(name(), indexedValueForSearch(value))), + MultiTermQuery.DOC_VALUES_REWRITE ); } query = new PrefixQuery(new Term(name(), indexedValueForSearch(value)), MultiTermQuery.DOC_VALUES_REWRITE); - } - else{ + } else { query = super.prefixQuery(value, method, caseInsensitive, context); } break; @@ -482,12 +480,11 @@ else if (hasDocValues()) { case DOC_VALUES_ONLY: failIfNoDocValues(); if (caseInsensitive) { - query = AutomatonQueries.caseInsensitivePrefixQuery( - (new Term(name(), indexedValueForSearch(value))), - MultiTermQuery.DOC_VALUES_REWRITE + query = AutomatonQueries.caseInsensitivePrefixQuery( + (new Term(name(), indexedValueForSearch(value))), + MultiTermQuery.DOC_VALUES_REWRITE ); - } - else { + } else { query = new PrefixQuery(new Term(name(), indexedValueForSearch(value)), MultiTermQuery.DOC_VALUES_REWRITE); } break; @@ -516,32 +513,30 @@ public Query regexpQuery( rewriteOverride = RewriteOverride.DEFAULT; } Query query = null; - switch(rewriteOverride) { + switch (rewriteOverride) { case DEFAULT: if (isSearchable() && hasDocValues()) { Query indexQuery = super.regexpQuery(value, syntaxFlags, matchFlags, maxDeterminizedStates, method, context); Query dvQuery = super.regexpQuery( - value, - syntaxFlags, - matchFlags, - maxDeterminizedStates, - MultiTermQuery.DOC_VALUES_REWRITE, - context + value, + syntaxFlags, + matchFlags, + maxDeterminizedStates, + MultiTermQuery.DOC_VALUES_REWRITE, + context ); - query = new IndexOrDocValuesQuery(indexQuery, dvQuery); - } - else if (hasDocValues()) { - query = new RegexpQuery( - new Term(name(), indexedValueForSearch(value)), - syntaxFlags, - matchFlags, - RegexpQuery.DEFAULT_PROVIDER, - maxDeterminizedStates, - MultiTermQuery.DOC_VALUES_REWRITE + query = new IndexOrDocValuesQuery(indexQuery, dvQuery); + } else if (hasDocValues()) { + query = new RegexpQuery( + new Term(name(), indexedValueForSearch(value)), + syntaxFlags, + matchFlags, + RegexpQuery.DEFAULT_PROVIDER, + maxDeterminizedStates, + MultiTermQuery.DOC_VALUES_REWRITE ); - } - else { - query = super.regexpQuery(value, syntaxFlags, matchFlags, maxDeterminizedStates, method, context); + } else { + query = super.regexpQuery(value, syntaxFlags, matchFlags, maxDeterminizedStates, method, context); } break; case INDEX_ONLY: @@ -551,20 +546,27 @@ else if (hasDocValues()) { case DOC_VALUES_ONLY: failIfNoDocValues(); query = new RegexpQuery( - new Term(name(), indexedValueForSearch(value)), - syntaxFlags, - matchFlags, - RegexpQuery.DEFAULT_PROVIDER, - maxDeterminizedStates, - MultiTermQuery.DOC_VALUES_REWRITE + new Term(name(), indexedValueForSearch(value)), + syntaxFlags, + matchFlags, + RegexpQuery.DEFAULT_PROVIDER, + maxDeterminizedStates, + MultiTermQuery.DOC_VALUES_REWRITE ); break; } - return query; + return query; } @Override - public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper, RewriteOverride rewriteOverride, QueryShardContext context) { + public Query rangeQuery( + Object lowerTerm, + Object upperTerm, + boolean includeLower, + boolean includeUpper, + RewriteOverride rewriteOverride, + QueryShardContext context + ) { if (context.allowExpensiveQueries() == false) { throw new OpenSearchException( "[range] queries on [text] or [keyword] fields cannot be executed when '" @@ -581,55 +583,53 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower case DEFAULT: if (isSearchable() && hasDocValues()) { Query indexQuery = new TermRangeQuery( - name(), - lowerTerm == null ? null : indexedValueForSearch(lowerTerm), - upperTerm == null ? null : indexedValueForSearch(upperTerm), - includeLower, - includeUpper + name(), + lowerTerm == null ? null : indexedValueForSearch(lowerTerm), + upperTerm == null ? null : indexedValueForSearch(upperTerm), + includeLower, + includeUpper ); Query dvQuery = new TermRangeQuery( - name(), - lowerTerm == null ? null : indexedValueForSearch(lowerTerm), - upperTerm == null ? null : indexedValueForSearch(upperTerm), - includeLower, - includeUpper, - MultiTermQuery.DOC_VALUES_REWRITE + name(), + lowerTerm == null ? null : indexedValueForSearch(lowerTerm), + upperTerm == null ? null : indexedValueForSearch(upperTerm), + includeLower, + includeUpper, + MultiTermQuery.DOC_VALUES_REWRITE ); query = new IndexOrDocValuesQuery(indexQuery, dvQuery); - } - else if (hasDocValues()) { + } else if (hasDocValues()) { query = new TermRangeQuery( - name(), - lowerTerm == null ? null : indexedValueForSearch(lowerTerm), - upperTerm == null ? null : indexedValueForSearch(upperTerm), - includeLower, - includeUpper, - MultiTermQuery.DOC_VALUES_REWRITE + name(), + lowerTerm == null ? null : indexedValueForSearch(lowerTerm), + upperTerm == null ? null : indexedValueForSearch(upperTerm), + includeLower, + includeUpper, + MultiTermQuery.DOC_VALUES_REWRITE ); - } - else { + } else { query = super.rangeQuery(lowerTerm, upperTerm, includeLower, includeUpper, context); } break; case INDEX_ONLY: failIfNotIndexed(); query = new TermRangeQuery( - name(), - lowerTerm == null ? null : indexedValueForSearch(lowerTerm), - upperTerm == null ? null : indexedValueForSearch(upperTerm), - includeLower, - includeUpper + name(), + lowerTerm == null ? null : indexedValueForSearch(lowerTerm), + upperTerm == null ? null : indexedValueForSearch(upperTerm), + includeLower, + includeUpper ); break; case DOC_VALUES_ONLY: failIfNoDocValues(); query = new TermRangeQuery( - name(), - lowerTerm == null ? null : indexedValueForSearch(lowerTerm), - upperTerm == null ? null : indexedValueForSearch(upperTerm), - includeLower, - includeUpper, - MultiTermQuery.DOC_VALUES_REWRITE + name(), + lowerTerm == null ? null : indexedValueForSearch(lowerTerm), + upperTerm == null ? null : indexedValueForSearch(upperTerm), + includeLower, + includeUpper, + MultiTermQuery.DOC_VALUES_REWRITE ); break; } @@ -671,8 +671,7 @@ public Query fuzzyQuery( context ); query = new IndexOrDocValuesQuery(indexQuery, dvQuery); - } - else if (hasDocValues()) { + } else if (hasDocValues()) { query = new FuzzyQuery( new Term(name(), indexedValueForSearch(value)), fuzziness.asDistance(BytesRefs.toString(value)), @@ -681,8 +680,7 @@ else if (hasDocValues()) { transpositions, MultiTermQuery.DOC_VALUES_REWRITE ); - } - else { + } else { query = super.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, method, context); } break; @@ -702,7 +700,7 @@ else if (hasDocValues()) { ); break; } - return query; + return query; } @Override diff --git a/server/src/main/java/org/opensearch/index/mapper/MappedFieldType.java b/server/src/main/java/org/opensearch/index/mapper/MappedFieldType.java index 1d26cc30270d6..dd32eb9a37392 100644 --- a/server/src/main/java/org/opensearch/index/mapper/MappedFieldType.java +++ b/server/src/main/java/org/opensearch/index/mapper/MappedFieldType.java @@ -295,30 +295,30 @@ public Query fuzzyQuery( } public Query fuzzyQuery( - Object value, - Fuzziness fuzziness, - int prefixLength, - int maxExpansions, - boolean transpositions, - @Nullable MultiTermQuery.RewriteMethod method, - @Nullable RewriteOverride rewriteOverride, - QueryShardContext context + Object value, + Fuzziness fuzziness, + int prefixLength, + int maxExpansions, + boolean transpositions, + @Nullable MultiTermQuery.RewriteMethod method, + @Nullable RewriteOverride rewriteOverride, + QueryShardContext context ) { throw new IllegalArgumentException( - "Can only use fuzzy queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" + "Can only use fuzzy queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" ); } public Query prefixQuery( - String value, - @Nullable MultiTermQuery.RewriteMethod method, - @Nullable RewriteOverride rewriteOverride, - boolean caseInsensitve, - QueryShardContext context + String value, + @Nullable MultiTermQuery.RewriteMethod method, + @Nullable RewriteOverride rewriteOverride, + boolean caseInsensitve, + QueryShardContext context ) { throw new QueryShardException( - context, - "Can only use prefix queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" + context, + "Can only use prefix queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" ); } @@ -356,16 +356,17 @@ public Query wildcardQuery( "Can only use wildcard queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" ); } + public Query wildcardQuery( - String value, - @Nullable MultiTermQuery.RewriteMethod method, - @Nullable RewriteOverride rewriteOverride, - boolean caseInsensitve, - QueryShardContext context + String value, + @Nullable MultiTermQuery.RewriteMethod method, + @Nullable RewriteOverride rewriteOverride, + boolean caseInsensitve, + QueryShardContext context ) { throw new QueryShardException( - context, - "Can only use wildcard queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" + context, + "Can only use wildcard queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" ); } @@ -392,17 +393,17 @@ public Query regexpQuery( } public Query regexpQuery( - String value, - int syntaxFlags, - int matchFlags, - int maxDeterminizedStates, - @Nullable MultiTermQuery.RewriteMethod method, - @Nullable RewriteOverride rewriteOverride, - QueryShardContext context + String value, + int syntaxFlags, + int matchFlags, + int maxDeterminizedStates, + @Nullable MultiTermQuery.RewriteMethod method, + @Nullable RewriteOverride rewriteOverride, + QueryShardContext context ) { throw new QueryShardException( - context, - "Can only use regexp queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" + context, + "Can only use regexp queries on keyword and text fields - not on [" + name + "] which is of type [" + typeName() + "]" ); } diff --git a/server/src/main/java/org/opensearch/index/mapper/SimpleMappedFieldType.java b/server/src/main/java/org/opensearch/index/mapper/SimpleMappedFieldType.java index 16cde2b04612b..70c0da3e42dd6 100644 --- a/server/src/main/java/org/opensearch/index/mapper/SimpleMappedFieldType.java +++ b/server/src/main/java/org/opensearch/index/mapper/SimpleMappedFieldType.java @@ -86,7 +86,14 @@ protected Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLo throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support range queries"); } - protected Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper,RewriteOverride rewriteOverride, QueryShardContext context) { + protected Query rangeQuery( + Object lowerTerm, + Object upperTerm, + boolean includeLower, + boolean includeUpper, + RewriteOverride rewriteOverride, + QueryShardContext context + ) { throw new IllegalArgumentException("Field [" + name() + "] of type [" + typeName() + "] does not support range queries"); } diff --git a/server/src/main/java/org/opensearch/index/query/PrefixQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/PrefixQueryBuilder.java index 327dc655b0595..1cfc55045ed61 100644 --- a/server/src/main/java/org/opensearch/index/query/PrefixQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/PrefixQueryBuilder.java @@ -176,7 +176,6 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx String rewrite = null; String rewrite_override = null; - String queryName = null; float boost = AbstractQueryBuilder.DEFAULT_BOOST; boolean caseInsensitive = DEFAULT_CASE_INSENSITIVITY; @@ -204,7 +203,7 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx caseInsensitive = parser.booleanValue(); } else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) { rewrite_override = parser.textOrNull(); - }else { + } else { throw new ParsingException( parser.getTokenLocation(), "[prefix] query does not support [" + currentFieldName + "]" @@ -219,7 +218,11 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx } } - return new PrefixQueryBuilder(fieldName, value).rewrite(rewrite).boost(boost).queryName(queryName).caseInsensitive(caseInsensitive).rewrite_override(rewrite_override); + return new PrefixQueryBuilder(fieldName, value).rewrite(rewrite) + .boost(boost) + .queryName(queryName) + .caseInsensitive(caseInsensitive) + .rewrite_override(rewrite_override); } @Override @@ -273,7 +276,7 @@ protected boolean doEquals(PrefixQueryBuilder other) { return Objects.equals(fieldName, other.fieldName) && Objects.equals(value, other.value) && Objects.equals(rewrite, other.rewrite) - && Objects.equals(rewrite_override, other.rewrite_override) + && Objects.equals(rewrite_override, other.rewrite_override) && Objects.equals(caseInsensitive, other.caseInsensitive); } } diff --git a/server/src/main/java/org/opensearch/index/query/RangeQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/RangeQueryBuilder.java index 36a8f425a2ccd..f497f2f66a5ee 100644 --- a/server/src/main/java/org/opensearch/index/query/RangeQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/RangeQueryBuilder.java @@ -78,7 +78,6 @@ public class RangeQueryBuilder extends AbstractQueryBuilder i private static final ParseField RELATION_FIELD = new ParseField("relation"); private static final ParseField REWRITE_OVERRIDE = new ParseField("rewrite_override"); - private final String fieldName; private Object from; private Object to; @@ -381,7 +380,6 @@ public static RangeQueryBuilder fromXContent(XContentParser parser) throws IOExc String relation = null; String rewrite_override = null; - String currentFieldName = null; XContentParser.Token token; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -426,7 +424,7 @@ public static RangeQueryBuilder fromXContent(XContentParser parser) throws IOExc queryName = parser.text(); } else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) { rewrite_override = parser.textOrNull(); - }else { + } else { throw new ParsingException( parser.getTokenLocation(), "[range] query does not support [" + currentFieldName + "]" @@ -565,6 +563,6 @@ protected boolean doEquals(RangeQueryBuilder other) { && Objects.equals(includeLower, other.includeLower) && Objects.equals(includeUpper, other.includeUpper) && Objects.equals(format, other.format) - && Objects.equals(rewrite_override, other.rewrite_override); + && Objects.equals(rewrite_override, other.rewrite_override); } } diff --git a/server/src/main/java/org/opensearch/index/query/RegexpQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/RegexpQueryBuilder.java index cf65e44902677..cc339e7b3e312 100644 --- a/server/src/main/java/org/opensearch/index/query/RegexpQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/RegexpQueryBuilder.java @@ -271,7 +271,7 @@ public static RegexpQueryBuilder fromXContent(XContentParser parser) throws IOEx queryName = parser.text(); } else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) { rewrite_override = parser.textOrNull(); - }else { + } else { throw new ParsingException( parser.getTokenLocation(), "[regexp] query does not support [" + currentFieldName + "]" @@ -356,6 +356,7 @@ protected boolean doEquals(RegexpQueryBuilder other) { && Objects.equals(syntaxFlagsValue, other.syntaxFlagsValue) && Objects.equals(caseInsensitive, other.caseInsensitive) && Objects.equals(maxDeterminizedStates, other.maxDeterminizedStates) - && Objects.equals(rewrite, other.rewrite) && Objects.equals(rewrite_override, other.rewrite_override); + && Objects.equals(rewrite, other.rewrite) + && Objects.equals(rewrite_override, other.rewrite_override); } } diff --git a/server/src/main/java/org/opensearch/index/query/WildcardQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/WildcardQueryBuilder.java index 03007e68b138f..5b95483fbe0d9 100644 --- a/server/src/main/java/org/opensearch/index/query/WildcardQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/WildcardQueryBuilder.java @@ -217,9 +217,9 @@ public static WildcardQueryBuilder fromXContent(XContentParser parser) throws IO caseInsensitive = parser.booleanValue(); } else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { queryName = parser.text(); - } else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) { + } else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) { rewrite_override = parser.textOrNull(); - }else { + } else { throw new ParsingException( parser.getTokenLocation(), "[wildcard] query does not support [" + currentFieldName + "]" @@ -237,7 +237,8 @@ public static WildcardQueryBuilder fromXContent(XContentParser parser) throws IO return new WildcardQueryBuilder(fieldName, value).rewrite(rewrite) .boost(boost) .queryName(queryName) - .caseInsensitive(caseInsensitive).rewrite_override(rewrite_override); + .caseInsensitive(caseInsensitive) + .rewrite_override(rewrite_override); } @Override @@ -288,6 +289,6 @@ protected boolean doEquals(WildcardQueryBuilder other) { && Objects.equals(value, other.value) && Objects.equals(rewrite, other.rewrite) && Objects.equals(caseInsensitive, other.caseInsensitive) - && Objects.equals(rewrite_override, other.rewrite_override); + && Objects.equals(rewrite_override, other.rewrite_override); } } diff --git a/server/src/main/java/org/opensearch/search/aggregations/bucket/BucketsAggregator.java b/server/src/main/java/org/opensearch/search/aggregations/bucket/BucketsAggregator.java index c85c61f6da29e..eef427754f535 100644 --- a/server/src/main/java/org/opensearch/search/aggregations/bucket/BucketsAggregator.java +++ b/server/src/main/java/org/opensearch/search/aggregations/bucket/BucketsAggregator.java @@ -76,7 +76,7 @@ public abstract class BucketsAggregator extends AggregatorBase { public BucketsAggregator( String name, - AggregatorFactories factories, + AggregatorFactories factories, SearchContext context, Aggregator parent, CardinalityUpperBound bucketCardinality,