-
Type: Improvement
-
Status: Open
-
Priority: Minor
-
Resolution: Unresolved
-
Affects Version/s: 7.10
-
Fix Version/s: QualifiedToSchedule
-
Component/s: Elasticsearch
-
Tags:
The filters on metadata (type, facets, lifecycle state ...) contribute to the document scoring. The score is not same for each document which sometimes results in a weird result order. Some results for a match query (OR) which contains all the keywords can appear after results that contains only some of the keywords because of the filters contribution (made a test with the API passthrough with explain set to true)
The elasticsearch documentation says that filters (ES) must be used instead of query (and that filters are faster than queries):
- filter in the "filtered" query in ES 1.x
https://www.elastic.co/guide/en/elasticsearch/reference/1.7/query-dsl-filtered-query.html - filter in the the "bool" query in ES 2.x
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
below is an example with ES 1.x
"query": { "filtered": { "query": { "bool": { "must": [ { "match": { "_all": { "query": "headache relief", "operator": "OR", "analyzer": "en_search_analyzer", "fuzziness": "AUTO" } } } ] } }, "filter": { "bool": { "must": [ { "term": { "ecm:isVersion": "0" } }, { "term": { "ecm:primaryType": "Article" } }, { "term": { "ecm:currentLifeCycleState": "approved" } } ], "must_not": [ { "term": { "ecm:mixinType": "HiddenInNavigation" } } ] } } } }
instead of
"query" : { "bool" : { "must" : [ { "match" : { "_all" : { "query" : "headache relief", "type" : "boolean", "operator" : "OR", "analyzer" : "en_search_analyzer", "fuzziness" : "AUTO" } } }, { "bool" : { "must" : [ { "constant_score" : { "filter" : { "not" : { "filter" : { "term" : { "ecm:mixinType" : "HiddenInNavigation" } } } } } }, { "constant_score" : { "filter" : { "term" : { "ecm:isVersion" : "0" } } } }, { "constant_score" : { "filter" : { "not" : { "filter" : { "term" : {