Avoid hitting max clause limit with the default value of default_field
#102378
Labels
:Search/Search
Search-related issues that do not fall into other categories
Team:Search
Meta label for search team
When not specifying a value for
index.query.default_field
, Elasticsearch uses*
elasticsearch/server/src/main/java/org/elasticsearch/index/IndexSettings.java
Lines 57 to 59 in 7e66983
which makes it resolve all searchable fields that have values in the index. When it resolves too many fields, an error is thrown to guard against excessive memory usage.
elasticsearch/server/src/main/java/org/elasticsearch/index/search/QueryParserHelper.java
Lines 154 to 164 in 7e66983
While the limits for the max number of boolean clauses is relatively generous (at least 1024, the exact value depends on the allocated CPU and memory count), there's still a risk of hitting this limit when increasing
index.mapping.total_fields.limit
from the default value of 1000.elasticsearch/server/src/main/java/org/elasticsearch/search/SearchUtils.java
Line 34 in 7e66983
At the moment, Fleet sets the
total_fields.limit
to 10k by default: https://github.com/elastic/kibana/blob/6775419c0bd6606fa1bbe9ea7cf512dcd6e82093/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.ts#L374The way integrations guard against hitting max clause limit is that they auto-generate the
default_field
based on the fields that the package declares: https://github.com/elastic/kibana/blob/6775419c0bd6606fa1bbe9ea7cf512dcd6e82093/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/default_settings.ts#L82. As discussed in #99872, we want to remove this and instead rely on the defaultdefault_field
in order to be able to use theecs@mappings
component template rather than the fields that the package defines. This will also make it possible for users to search by fields that are dynamically mapped today (such as labels).Once #96235 is merged, we may want to lower the defaults in Fleet. However, we may not be able to do this for all integrations and users can always manually increase the field limit.
All of this is to say that I think we should guard against running into the max clause limit so that using the default value for
default_field
never runs the risk of causing a search to fail.That seems to be relatively straightforward by limiting the number of fields we resolve here:
elasticsearch/server/src/main/java/org/elasticsearch/index/search/QueryParserHelper.java
Line 80 in b65e871
For the all field (
*
)elasticsearch/server/src/main/java/org/elasticsearch/index/search/QueryParserHelper.java
Line 77 in b65e871
We can retain the logic of failing when a more specific set of fields is selected (such as
labels.*
). What's most important is that we don't fail in the default case.cc @ruflin @javanna
The text was updated successfully, but these errors were encountered: