loopbackio / loopback-connector-elastic-search

Strongloop Loopback connector for Elasticsearch
MIT License
79 stars 56 forks source link

deleteByQuery should use a filter instead of a query for much better performance #29

Open mrfelton opened 8 years ago

mrfelton commented 8 years ago

Currently, destroyAll issues a deleteByQuery operation with a query. Using a query causes ES to generate scores as part of the process and as a result has additional overhead.

As a general rule, filters should be used instead of queries: for binary yes/no searches for queries on exact values

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filters.html

As a general rule, queries should be used instead of filters: for full text search where the result depends on a relevance score

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html

Filters are very handy since they perform an order of magnitude better than plain queries since no scoring is performed and they are automatically cached.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html