Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.BytesRefs;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.SuggestingErrorOnUnknown;
import org.elasticsearch.xcontent.AbstractObjectParser;
import org.elasticsearch.xcontent.FilterXContentParser;
Expand Down Expand Up @@ -49,8 +50,8 @@ public abstract class AbstractQueryBuilder<QB extends AbstractQueryBuilder<QB>>
public static final float DEFAULT_BOOST = 1.0f;
public static final ParseField NAME_FIELD = new ParseField("_name");
public static final ParseField BOOST_FIELD = new ParseField("boost");

private static int maxNestedDepth = 20;
// We set the default value for tests that don't go through SearchModule
private static int maxNestedDepth = INDICES_MAX_NESTED_DEPTH_SETTING.getDefault(Settings.EMPTY);

protected String queryName;
protected float boost = DEFAULT_BOOST;
Expand Down Expand Up @@ -427,6 +428,10 @@ public static void setMaxNestedDepth(int maxNestedDepth) {
AbstractQueryBuilder.maxNestedDepth = maxNestedDepth;
}

public static int getMaxNestedDepth() {
return maxNestedDepth;
}

@Override
public final String toString() {
return Strings.toString(this, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.index.query.AbstractQueryBuilder;
import org.elasticsearch.index.query.CommonTermsQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryRewriteContext;
Expand Down Expand Up @@ -779,4 +780,19 @@ public List<SearchPlugin.QuerySpec<?>> getQueries() {
assertTrue(RestApiVersion.minimumSupported().matches(compatEntry.get(0).restApiCompatibility));
assertFalse(RestApiVersion.current().matches(compatEntry.get(0).restApiCompatibility));
}

public void testDefaultMaxNestedDepth() {
new SearchModule(Settings.EMPTY, emptyList());
assertEquals(
SearchModule.INDICES_MAX_NESTED_DEPTH_SETTING.getDefault(Settings.EMPTY).intValue(),
AbstractQueryBuilder.getMaxNestedDepth()
);
}

public void testCustomMaxNestedDepth() {
int customValue = randomIntBetween(1, 100);
Settings settings = Settings.builder().put(SearchModule.INDICES_MAX_NESTED_DEPTH_SETTING.getKey(), customValue).build();
new SearchModule(settings, emptyList());
assertEquals(customValue, AbstractQueryBuilder.getMaxNestedDepth());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,15 @@ protected QB createQueryWithInnerQuery(QueryBuilder queryBuilder) {
throw new UnsupportedOperationException();
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/90984")
public void testMaxNestedDepth() throws IOException {
QB query = null;
try {
query = createQueryWithInnerQuery(new MatchAllQueryBuilder());
} catch (UnsupportedOperationException e) {
assumeNoException("Runs only for queries that support nesting", e);
}
int maxDepth;
if (frequently()) {
maxDepth = randomIntBetween(3, 5);
AbstractQueryBuilder.setMaxNestedDepth(maxDepth);
} else {
maxDepth = INDICES_MAX_NESTED_DEPTH_SETTING.getDefault(Settings.EMPTY);
}
int maxDepth = randomIntBetween(3, 5);
AbstractQueryBuilder.setMaxNestedDepth(maxDepth);
try {
for (int i = 1; i < maxDepth - 1; i++) {
query = createQueryWithInnerQuery(query);
Expand Down