Description
Historically we have done our best to make sure that queries are unlikely to get slow:
- fields are indexed by default
- fields require indexing to enable searching
- except the
script
query, none of our queries perform linear scans
Unfortunately, this doesn't cover all cases, and you can still run range
queries on keyword
fields or queries with leading wildcards on text
fields, which can be super slow as well. It makes the above rules feel somewhat arbitrary. Moreover, lots of users have rarely queried fields, and they'd rather accept that the rare queries that use these fields are slower than take the indexing and space overhead.
There are plans to enable more options that trade search speed for more flexibility, lower disk usage or lighter indexing load. One issue with this move is that we might get an increasing number of users wondering about why their queries are slow. For instance it's easy to enable an option that makes search slower when small volumes of data are indexed, then forget about it, and months later have issues with 10x larger data volumes and queries that no longer meet SLAs.
One way to make it less surprising would be to push the information to the user, so that it would be obvious that something in the query is not optimal, e.g.
- it uses a script query,
- it has a prefix query on a
text
field andindex_prefixes
is not enabled, - it uses a wildcard query with a leading wildcard,
- etc.
The way I'm thinking it could work would be by making Elasticsearch return this information in an HTTP header and make Kibana recognize it, so that it could insert a visual indication on visualizations that use slow queries.
Relates to #29050, which is about disabling slow queries entirely