loopback-connector-elastic-search icon indicating copy to clipboard operation
loopback-connector-elastic-search copied to clipboard

Use only filter context within queries

Open wolfgang-s opened this issue 7 years ago • 0 comments

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

wolfgang-s avatar Mar 08 '17 10:03 wolfgang-s