Performance of elastic queries
The top-level filter
element in the first request has very special function in Elasticsearch. It's used to filter search result without affecting facets. In order to avoid interfering with facets, this filter is applied during collection of results and not during searching, which causes its slow performance. Using top-level filter
without facets makes very little sense because filtered
and constant_score
queries typically provide much better performance. If verbosity of filtered
query with match_all
bothers you, you can rewrite your second request into equivalent constant_score
query:
{ "query": { "constant_score": { "filter": { "term": { "id": "123456" } } } }}