Skip to content

Commit

Permalink
fix(index): restrict number of prefix values that can be simultaneously.
Browse files Browse the repository at this point in the history
...queried to 1000 (ES defaults to 1024, there is extra room for other
clauses before ES would respond with an error)
  • Loading branch information
cmark committed Jul 4, 2022
1 parent 7f16e9f commit eb6df3b
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2021 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2011-2022 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,13 +17,22 @@

import java.util.stream.Collectors;

import org.elasticsearch.common.util.iterable.Iterables;

import com.b2international.commons.exceptions.BadRequestException;

/**
* @since 5.0
*/
public final class PrefixPredicate extends SetPredicate<String> {

PrefixPredicate(String field, Iterable<String> arguments) {
super(field, arguments);
final long numberOfTerms = Iterables.size(arguments);
// XXX the usual maxClauseCount default value in ES is 1024, so allow room for other clauses before responding with an error to the caller
if (numberOfTerms > 1000) {
throw new BadRequestException("Too may ('%s') prefix query clauses supplied for '%s' field.", numberOfTerms, field);
}
}

@Override
Expand Down

0 comments on commit eb6df3b

Please sign in to comment.