Elasticsearch Filtered query vs Filter [duplicate]

The difference is related to performance. “filter” on top level is always executed after the query. This means the query is executed on all documents, score is computed for all documents etc. – and only then documents not matching filter are excluded.

With “filtered” query there is a possibility that ES will optimize this computation, e.g. first executing the filter, then executing query on a limited set of documents, saving time on testing the documents that don’t match the filter against the query, and on computing scores for them if they do match the query.

If you are performing multiple queries with same filter, then there are even more advantages: the filter may be cached, improving performance of each query even further. This applies to your example: “term” filters are cached by default.

You also can explicitly control the execution of “filtered” query (see the documentation) to optimize it for your particular use case.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)