loopbackio / loopback-connector-elastic-search

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

Use only filter context within queries #88

Open wolfgang-s opened 7 years ago

wolfgang-s commented 7 years ago

Sind we are never interested in the score of a document (How well does something match), all queries should execute as a filter.

Currently we do not use filter context, which makes the queries slow (and not cachable in memory)

https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-filter-context.html

My suggestions is to use https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-dsl-constant-score-query.html

or https://www.elastic.co/guide/en/elasticsearch/reference/5.1/query-dsl-bool-query.html with "filter" or "must_not" -> but this is only for AND queries, no OR -> for findById for example

A simple change, and fast queries we could just replace (buildWhere function)

query: { bool: { must: [], should: [], must_not: [] } }

with

query: { constant_score: { filter: { bool: { must: [], should: [], must_not: [] } } } }

What do you think? Supported since V1