diff --git a/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizingVisitor.java b/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizingVisitor.java new file mode 100644 index 0000000000000..007480bb2e7bd --- /dev/null +++ b/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizingVisitor.java @@ -0,0 +1,71 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.action.search; + +import org.apache.lucene.search.BooleanClause; +import org.opensearch.index.query.BoolQueryBuilder; +import org.opensearch.index.query.MatchPhraseQueryBuilder; +import org.opensearch.index.query.MatchQueryBuilder; +import org.opensearch.index.query.MultiMatchQueryBuilder; +import org.opensearch.index.query.QueryBuilder; +import org.opensearch.index.query.QueryBuilderVisitor; +import org.opensearch.index.query.QueryStringQueryBuilder; +import org.opensearch.index.query.RangeQueryBuilder; +import org.opensearch.index.query.RegexpQueryBuilder; +import org.opensearch.index.query.TermQueryBuilder; +import org.opensearch.index.query.WildcardQueryBuilder; +import org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder; +import org.opensearch.telemetry.metrics.tags.Tags; + +/** + * Class to visit the querybuilder tree and also track the level information. + * Increments the counters related to Search Query type. + */ +public class SearchQueryCategorizingVisitor implements QueryBuilderVisitor { + private final int level; + private final SearchQueryCounters searchQueryCounters; + + public SearchQueryCategorizingVisitor(SearchQueryCounters searchQueryCounters) { + this(searchQueryCounters, 0); + } + + private SearchQueryCategorizingVisitor(SearchQueryCounters counters, int level) { + this.searchQueryCounters = counters; + this.level = level; + } + public void accept(QueryBuilder qb) { + if (qb instanceof BoolQueryBuilder) { + searchQueryCounters.boolCounter.add(1, Tags.create().addTag("level", level)); + } else if (qb instanceof FunctionScoreQueryBuilder) { + searchQueryCounters.functionScoreCounter.add(1, Tags.create().addTag("level", level)); + } else if (qb instanceof MatchQueryBuilder) { + searchQueryCounters.matchCounter.add(1, Tags.create().addTag("level", level)); + } else if (qb instanceof MatchPhraseQueryBuilder) { + searchQueryCounters.matchPhrasePrefixCounter.add(1, Tags.create().addTag("level", level)); + } else if (qb instanceof MultiMatchQueryBuilder) { + searchQueryCounters.multiMatchCounter.add(1, Tags.create().addTag("level", level)); + } else if (qb instanceof QueryStringQueryBuilder) { + searchQueryCounters.queryStringQueryCounter.add(1, Tags.create().addTag("level", level)); + } else if (qb instanceof RangeQueryBuilder) { + searchQueryCounters.rangeCounter.add(1, Tags.create().addTag("level", level)); + } else if (qb instanceof RegexpQueryBuilder) { + searchQueryCounters.regexCounter.add(1, Tags.create().addTag("level", level)); + } else if (qb instanceof TermQueryBuilder) { + searchQueryCounters.termCounter.add(1, Tags.create().addTag("level", level)); + } else if (qb instanceof WildcardQueryBuilder) { + searchQueryCounters.wildcardCounter.add(1, Tags.create().addTag("level", level)); + } else { + searchQueryCounters.otherQueryCounter.add(1, Tags.create().addTag("level", level)); + } + } + + public QueryBuilderVisitor getChildVisitor(BooleanClause.Occur occur) { + return new SearchQueryCategorizingVisitor(searchQueryCounters, level + 1); + } +} diff --git a/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizor.java b/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizor.java index 25b360ab69391..64526fd2fc32d 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizor.java +++ b/server/src/main/java/org/opensearch/action/search/SearchQueryCategorizor.java @@ -10,24 +10,17 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.lucene.search.BooleanClause; -import org.opensearch.index.query.BoolQueryBuilder; -import org.opensearch.index.query.MatchPhraseQueryBuilder; -import org.opensearch.index.query.MatchQueryBuilder; -import org.opensearch.index.query.MultiMatchQueryBuilder; import org.opensearch.index.query.QueryBuilder; import org.opensearch.index.query.QueryBuilderVisitor; import org.opensearch.index.query.QueryShapeVisitor; -import org.opensearch.index.query.QueryStringQueryBuilder; -import org.opensearch.index.query.RangeQueryBuilder; -import org.opensearch.index.query.RegexpQueryBuilder; -import org.opensearch.index.query.TermQueryBuilder; -import org.opensearch.index.query.WildcardQueryBuilder; -import org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder; +import org.opensearch.search.aggregations.AggregatorFactories; import org.opensearch.search.builder.SearchSourceBuilder; +import org.opensearch.search.sort.SortBuilder; import org.opensearch.telemetry.metrics.MetricsRegistry; import org.opensearch.telemetry.metrics.tags.Tags; +import java.util.List; + /** * Class to categorize the search queries based on the type and increment the relevant counters. * Class also logs the query shape. @@ -46,51 +39,31 @@ public void categorize(SearchSourceBuilder source) { QueryBuilder topLevelQueryBuilder = source.query(); logQueryShape(topLevelQueryBuilder); + incrementQueryTypeCounters(topLevelQueryBuilder); + incrementQueryAggregationCounters(source.aggregations()); + incrementQuerySortCounters(source.sorts()); + } - incrementQueryCounters(topLevelQueryBuilder); + private void incrementQuerySortCounters(List> sorts) { + if (sorts.size() > 0) { + searchQueryCounters.sortCounter.add(1); + } } - private static void incrementQueryCounters(QueryBuilder topLevelQueryBuilder) { - // Increment the query counters using Metric Framework - QueryBuilderVisitor queryBuilderVisitor = new QueryBuilderVisitor() { - @Override - public void accept(QueryBuilder qb, int level) { - if (qb instanceof BoolQueryBuilder) { - searchQueryCounters.boolCounter.add(1, Tags.create().addTag("level", level)); - } else if (qb instanceof FunctionScoreQueryBuilder) { - searchQueryCounters.functionScoreCounter.add(1, Tags.create().addTag("level", level)); - } else if (qb instanceof MatchQueryBuilder) { - searchQueryCounters.matchCounter.add(1, Tags.create().addTag("level", level)); - } else if (qb instanceof MatchPhraseQueryBuilder) { - searchQueryCounters.matchPhrasePrefixCounter.add(1, Tags.create().addTag("level", level)); - } else if (qb instanceof MultiMatchQueryBuilder) { - searchQueryCounters.multiMatchCounter.add(1, Tags.create().addTag("level", level)); - } else if (qb instanceof QueryStringQueryBuilder) { - searchQueryCounters.queryStringQueryCounter.add(1, Tags.create().addTag("level", level)); - } else if (qb instanceof RangeQueryBuilder) { - searchQueryCounters.rangeCounter.add(1, Tags.create().addTag("level", level)); - } else if (qb instanceof RegexpQueryBuilder) { - searchQueryCounters.regexCounter.add(1, Tags.create().addTag("level", level)); - } else if (qb instanceof TermQueryBuilder) { - searchQueryCounters.termCounter.add(1, Tags.create().addTag("level", level)); - } else if (qb instanceof WildcardQueryBuilder) { - searchQueryCounters.wildcardCounter.add(1, Tags.create().addTag("level", level)); - } else { - searchQueryCounters.otherQueryCounter.add(1, Tags.create().addTag("level", level)); - } - } + private void incrementQueryAggregationCounters(AggregatorFactories.Builder aggregations) { + if (aggregations != null) { + searchQueryCounters.aggCounter.add(1); + } + } - @Override - public QueryBuilderVisitor getChildVisitor(BooleanClause.Occur occur) { - return this; - } - }; - topLevelQueryBuilder.visit(queryBuilderVisitor, 0); + private static void incrementQueryTypeCounters(QueryBuilder topLevelQueryBuilder) { + QueryBuilderVisitor searhQueryVisitor = new SearchQueryCategorizingVisitor(searchQueryCounters); + topLevelQueryBuilder.visit(searhQueryVisitor); } private static void logQueryShape(QueryBuilder topLevelQueryBuilder) { QueryShapeVisitor shapeVisitor = new QueryShapeVisitor(); - topLevelQueryBuilder.visit(shapeVisitor, 0); + topLevelQueryBuilder.visit(shapeVisitor); String queryShapeJson = shapeVisitor.prettyPrintTree(" "); log.debug("Query shape : " + queryShapeJson); } diff --git a/server/src/main/java/org/opensearch/action/search/SearchQueryCounters.java b/server/src/main/java/org/opensearch/action/search/SearchQueryCounters.java index 0bf7bf6e7f960..c0d8fabc6bf36 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchQueryCounters.java +++ b/server/src/main/java/org/opensearch/action/search/SearchQueryCounters.java @@ -28,6 +28,8 @@ public class SearchQueryCounters { public final Counter queryStringQueryCounter; public final Counter rangeCounter; public final Counter regexCounter; + + public final Counter sortCounter; public final Counter termCounter; public final Counter totalCounter; public final Counter wildcardCounter; @@ -36,7 +38,7 @@ public SearchQueryCounters(MetricsRegistry metricsRegistry) { this.metricsRegistry = metricsRegistry; this.aggCounter = metricsRegistry.createCounter( "aggSearchQueryCounter", - "Counter for the number of top level and nested agg search queries", + "Counter for the number of top level agg search queries", "0" ); this.boolCounter = metricsRegistry.createCounter( @@ -84,6 +86,11 @@ public SearchQueryCounters(MetricsRegistry metricsRegistry) { "Counter for the number of top level and nested regex search queries", "0" ); + this.sortCounter = metricsRegistry.createCounter( + "sortSearchQueryCounter", + "Counter for the number of top level sort search queries", + "0" + ); this.termCounter = metricsRegistry.createCounter( "termSearchQueryCounter", "Counter for the number of top level and nested term search queries", diff --git a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java index 9cb1ff9df6078..4fa342893d533 100644 --- a/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java +++ b/server/src/main/java/org/opensearch/action/search/TransportSearchAction.java @@ -60,6 +60,7 @@ import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Setting.Property; import org.opensearch.common.unit.TimeValue; +import org.opensearch.common.util.FeatureFlags; import org.opensearch.common.util.concurrent.AtomicArray; import org.opensearch.common.util.concurrent.CountDown; import org.opensearch.core.action.ActionListener; @@ -173,6 +174,8 @@ public class TransportSearchAction extends HandledTransportAction rewriteListener = ActionListener.wrap(source -> { if (source != searchRequest.source()) { diff --git a/server/src/main/java/org/opensearch/common/util/FeatureFlags.java b/server/src/main/java/org/opensearch/common/util/FeatureFlags.java index 4e9b417e3433b..8f5bc00f0f7eb 100644 --- a/server/src/main/java/org/opensearch/common/util/FeatureFlags.java +++ b/server/src/main/java/org/opensearch/common/util/FeatureFlags.java @@ -60,6 +60,11 @@ public class FeatureFlags { */ public static final String DATETIME_FORMATTER_CACHING = "opensearch.experimental.optimization.datetime_formatter_caching.enabled"; + /** + * Gates the query categorization by type feature. + */ + public static final String QUERY_CATEOGORIZATION = "opensearch.experimental.feature.query_categorization.enabled"; + /** * Should store the settings from opensearch.yml. */ @@ -122,4 +127,10 @@ public static boolean isEnabled(Setting featureFlag) { true, Property.NodeScope ); + + public static final Setting QUERY_CATEGORIZATION_SETTING = Setting.boolSetting( + QUERY_CATEOGORIZATION, + false, + Property.NodeScope + ); } diff --git a/server/src/main/java/org/opensearch/index/query/BoolQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/BoolQueryBuilder.java index e870de23cd5fd..c44a7ef6a397c 100644 --- a/server/src/main/java/org/opensearch/index/query/BoolQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/BoolQueryBuilder.java @@ -429,30 +429,30 @@ private static boolean rewriteClauses( } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); if (mustClauses.isEmpty() == false) { QueryBuilderVisitor subVisitor = visitor.getChildVisitor(Occur.MUST); for (QueryBuilder mustClause : mustClauses) { - mustClause.visit(subVisitor, level + 1); + mustClause.visit(subVisitor); } } if (shouldClauses.isEmpty() == false) { QueryBuilderVisitor subVisitor = visitor.getChildVisitor(Occur.SHOULD); for (QueryBuilder shouldClause : shouldClauses) { - shouldClause.visit(subVisitor, level + 1); + shouldClause.visit(subVisitor); } } if (mustNotClauses.isEmpty() == false) { QueryBuilderVisitor subVisitor = visitor.getChildVisitor(Occur.MUST_NOT); for (QueryBuilder mustNotClause : mustNotClauses) { - mustNotClause.visit(subVisitor, level + 1); + mustNotClause.visit(subVisitor); } } if (filterClauses.isEmpty() == false) { QueryBuilderVisitor subVisitor = visitor.getChildVisitor(Occur.FILTER); for (QueryBuilder filterClause : filterClauses) { - filterClause.visit(subVisitor, level + 1); + filterClause.visit(subVisitor); } } diff --git a/server/src/main/java/org/opensearch/index/query/BoostingQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/BoostingQueryBuilder.java index c5070920ab4cd..1b52ae2f03605 100644 --- a/server/src/main/java/org/opensearch/index/query/BoostingQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/BoostingQueryBuilder.java @@ -255,13 +255,13 @@ protected void extractInnerHitBuilders(Map inner } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); if (positiveQuery != null) { - visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(positiveQuery, level + 1); + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(positiveQuery); } if (negativeQuery != null) { - visitor.getChildVisitor(BooleanClause.Occur.SHOULD).accept(negativeQuery, level + 1); + visitor.getChildVisitor(BooleanClause.Occur.SHOULD).accept(negativeQuery); } } } diff --git a/server/src/main/java/org/opensearch/index/query/ConstantScoreQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/ConstantScoreQueryBuilder.java index 2ede60d935210..b2764d29da80a 100644 --- a/server/src/main/java/org/opensearch/index/query/ConstantScoreQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/ConstantScoreQueryBuilder.java @@ -186,9 +186,9 @@ protected void extractInnerHitBuilders(Map inner } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); - visitor.getChildVisitor(BooleanClause.Occur.FILTER).accept(filterBuilder, level + 1); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); + visitor.getChildVisitor(BooleanClause.Occur.FILTER).accept(filterBuilder); } } diff --git a/server/src/main/java/org/opensearch/index/query/DisMaxQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/DisMaxQueryBuilder.java index bc26cfed53b07..bd8ec62f6c43e 100644 --- a/server/src/main/java/org/opensearch/index/query/DisMaxQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/DisMaxQueryBuilder.java @@ -249,12 +249,12 @@ protected void extractInnerHitBuilders(Map inner } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); if (queries.isEmpty() == false) { QueryBuilderVisitor subVisitor = visitor.getChildVisitor(BooleanClause.Occur.SHOULD); for (QueryBuilder subQb : queries) { - subVisitor.accept(subQb, level + 1); + subVisitor.accept(subQb); } } } diff --git a/server/src/main/java/org/opensearch/index/query/FieldMaskingSpanQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/FieldMaskingSpanQueryBuilder.java index f4859adacc194..1162689a54689 100644 --- a/server/src/main/java/org/opensearch/index/query/FieldMaskingSpanQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/FieldMaskingSpanQueryBuilder.java @@ -210,8 +210,8 @@ public String getWriteableName() { } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); - visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(queryBuilder, level + 1); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(queryBuilder); } } diff --git a/server/src/main/java/org/opensearch/index/query/QueryBuilder.java b/server/src/main/java/org/opensearch/index/query/QueryBuilder.java index 7d6c024846a1c..090f74c5be7fe 100644 --- a/server/src/main/java/org/opensearch/index/query/QueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/QueryBuilder.java @@ -99,10 +99,9 @@ default QueryBuilder rewrite(QueryRewriteContext queryShardContext) throws IOExc /** * Recurse through the QueryBuilder tree, visiting any child QueryBuilder. * @param visitor a query builder visitor to be called by each query builder in the tree. - * @param level level of the current query builder based on the QueryBuilder tree. 0 is top/root level. */ - default void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); + default void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); }; } diff --git a/server/src/main/java/org/opensearch/index/query/QueryBuilderVisitor.java b/server/src/main/java/org/opensearch/index/query/QueryBuilderVisitor.java index 4cae0f00d746d..af5a125f9dd95 100644 --- a/server/src/main/java/org/opensearch/index/query/QueryBuilderVisitor.java +++ b/server/src/main/java/org/opensearch/index/query/QueryBuilderVisitor.java @@ -18,9 +18,8 @@ public interface QueryBuilderVisitor { /** * Accept method is called when the visitor accepts the queryBuilder object to be traversed in the query tree. * @param qb is a queryBuilder object which is accepeted by the visitor. - * @param level level of the current query builder based on the QueryBuilder tree. 0 is top/root level. */ - void accept(QueryBuilder qb, int level); + void accept(QueryBuilder qb); /** * Fetches the child sub visitor from the main QueryBuilderVisitor Object. @@ -36,7 +35,7 @@ public interface QueryBuilderVisitor { */ QueryBuilderVisitor NO_OP_VISITOR = new QueryBuilderVisitor() { @Override - public void accept(QueryBuilder qb, int level) { + public void accept(QueryBuilder qb) { // Do nothing } diff --git a/server/src/main/java/org/opensearch/index/query/QueryShapeVisitor.java b/server/src/main/java/org/opensearch/index/query/QueryShapeVisitor.java index 6fd7a182c1fba..10f5774219032 100644 --- a/server/src/main/java/org/opensearch/index/query/QueryShapeVisitor.java +++ b/server/src/main/java/org/opensearch/index/query/QueryShapeVisitor.java @@ -25,7 +25,7 @@ public class QueryShapeVisitor implements QueryBuilderVisitor { private final Map> childVisitors = new EnumMap<>(BooleanClause.Occur.class); @Override - public void accept(QueryBuilder qb, int level) { + public void accept(QueryBuilder qb) { queryType.set(qb.getName()); } @@ -40,10 +40,10 @@ public QueryBuilderVisitor getChildVisitor(BooleanClause.Occur occur) { QueryShapeVisitor currentChild; @Override - public void accept(QueryBuilder qb, int level) { + public void accept(QueryBuilder qb) { currentChild = new QueryShapeVisitor(); childVisitorList.add(currentChild); - currentChild.accept(qb, level + 1); + currentChild.accept(qb); } @Override diff --git a/server/src/main/java/org/opensearch/index/query/SpanContainingQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/SpanContainingQueryBuilder.java index 781f522980511..32a19ea3e9b50 100644 --- a/server/src/main/java/org/opensearch/index/query/SpanContainingQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/SpanContainingQueryBuilder.java @@ -191,9 +191,9 @@ public String getWriteableName() { } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); - visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(big, level + 1); - visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(little, level + 1); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(big); + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(little); } } diff --git a/server/src/main/java/org/opensearch/index/query/SpanFirstQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/SpanFirstQueryBuilder.java index e51f4457cc0f1..bcbc64ddf386d 100644 --- a/server/src/main/java/org/opensearch/index/query/SpanFirstQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/SpanFirstQueryBuilder.java @@ -189,8 +189,8 @@ public String getWriteableName() { } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); - visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(matchBuilder, level + 1); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(matchBuilder); } } diff --git a/server/src/main/java/org/opensearch/index/query/SpanMultiTermQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/SpanMultiTermQueryBuilder.java index c27b8682eb8b6..96d03c91964e3 100644 --- a/server/src/main/java/org/opensearch/index/query/SpanMultiTermQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/SpanMultiTermQueryBuilder.java @@ -216,10 +216,10 @@ public String getWriteableName() { } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); if (multiTermQueryBuilder != null) { - visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(multiTermQueryBuilder, level + 1); + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(multiTermQueryBuilder); } } } diff --git a/server/src/main/java/org/opensearch/index/query/SpanNearQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/SpanNearQueryBuilder.java index d3573ec3e8684..30a1c29c29126 100644 --- a/server/src/main/java/org/opensearch/index/query/SpanNearQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/SpanNearQueryBuilder.java @@ -301,12 +301,12 @@ public String getWriteableName() { } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); if (this.clauses.isEmpty() == false) { QueryBuilderVisitor subVisitor = visitor.getChildVisitor(BooleanClause.Occur.MUST); for (QueryBuilder subQb : this.clauses) { - subVisitor.accept(subQb, level + 1); + subVisitor.accept(subQb); } } } diff --git a/server/src/main/java/org/opensearch/index/query/SpanNotQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/SpanNotQueryBuilder.java index 00d9e8014b533..59ec5b9d77fc8 100644 --- a/server/src/main/java/org/opensearch/index/query/SpanNotQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/SpanNotQueryBuilder.java @@ -287,14 +287,14 @@ public String getWriteableName() { } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); if (include != null) { - visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(include, level + 1); + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(include); } if (exclude != null) { - visitor.getChildVisitor(BooleanClause.Occur.MUST_NOT).accept(exclude, level + 1); + visitor.getChildVisitor(BooleanClause.Occur.MUST_NOT).accept(exclude); } } } diff --git a/server/src/main/java/org/opensearch/index/query/SpanOrQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/SpanOrQueryBuilder.java index f1b94f40c4bd7..fae1e318c66bd 100644 --- a/server/src/main/java/org/opensearch/index/query/SpanOrQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/SpanOrQueryBuilder.java @@ -191,12 +191,12 @@ public String getWriteableName() { } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); if (clauses.isEmpty() == false) { QueryBuilderVisitor subVisitor = visitor.getChildVisitor(BooleanClause.Occur.SHOULD); for (QueryBuilder subQb : this.clauses) { - subVisitor.accept(subQb, level + 1); + subVisitor.accept(subQb); } } } diff --git a/server/src/main/java/org/opensearch/index/query/SpanWithinQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/SpanWithinQueryBuilder.java index fb695842864d8..4d5a6dde61a70 100644 --- a/server/src/main/java/org/opensearch/index/query/SpanWithinQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/SpanWithinQueryBuilder.java @@ -200,9 +200,9 @@ public String getWriteableName() { } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); - visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(big, level + 1); - visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(little, level + 1); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(big); + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(little); } } diff --git a/server/src/main/java/org/opensearch/index/query/functionscore/ScriptScoreQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/functionscore/ScriptScoreQueryBuilder.java index 2145873f41f91..fe9ad200d44f0 100644 --- a/server/src/main/java/org/opensearch/index/query/functionscore/ScriptScoreQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/functionscore/ScriptScoreQueryBuilder.java @@ -227,11 +227,11 @@ protected void extractInnerHitBuilders(Map inner } @Override - public void visit(QueryBuilderVisitor visitor, int level) { - visitor.accept(this, level); + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); if (query != null) { QueryBuilderVisitor subVisitor = visitor.getChildVisitor(BooleanClause.Occur.MUST); - subVisitor.accept(query, level + 1); + subVisitor.accept(query); } } } diff --git a/test/framework/src/main/java/org/opensearch/test/telemetry/MockTelemetry.java b/test/framework/src/main/java/org/opensearch/test/telemetry/MockTelemetry.java index 95321a7009be9..a1801aa125148 100644 --- a/test/framework/src/main/java/org/opensearch/test/telemetry/MockTelemetry.java +++ b/test/framework/src/main/java/org/opensearch/test/telemetry/MockTelemetry.java @@ -12,6 +12,7 @@ import org.opensearch.telemetry.TelemetrySettings; import org.opensearch.telemetry.metrics.Counter; import org.opensearch.telemetry.metrics.MetricsTelemetry; +import org.opensearch.telemetry.metrics.noop.NoopCounter; import org.opensearch.telemetry.tracing.TracingTelemetry; import org.opensearch.test.telemetry.tracing.MockTracingTelemetry; @@ -37,7 +38,7 @@ public MetricsTelemetry getMetricsTelemetry() { return new MetricsTelemetry() { @Override public Counter createCounter(String name, String description, String unit) { - return null; + return NoopCounter.INSTANCE; } @Override