Assume I have a query that is quite slow due to the usage of many should
clauses (e.g. location based decay functions) in the bool
query on many documents. To increase the speed of the query I would like to reformulate the query in a hierarchical way so that easy to check queries like match
in the should clause are executed on all documents but more expensive queries like 2d decay functions are executed only on the top results, i.e. scores, returned by the easier queries. So it works like a pyramid and on each level I would be able to execute the next level only on the top n or top x% results (by score) of the current level.
How would I accomplish something like this? I read about the deprecated filter: {limit: {value: 10}}
query but it didn't work for me and I don't want to start using deprecated features. The terminate_after
parameter in the search api is interesting but seems to work only on the top level of the whole query. There is also the advanced min_score
parameter but that would require that I have a clue at query construction time about the range of my scores. In most cases this is not possible to know in advance. Also I'd like to avoid scripts if possible since on many productive ES installation this feature is disabled due to security concerns.
Does anyone know how I would do that? Thanks!