Guy Korland
Guy Korland

Reputation: 9568

Scores optimization for ElasticSEarch

We have a catalog of products stored in ElasticSearch. Each document looks like this:

{
   'family': 'products family'
   'category': 'products category' 
   'name': 'product name'
   'description': 'product description'
}

We are trying to build a query that will get the fuzzy match for a search term and will score the results by the following order of fields:

Is there a way to do it?

Upvotes: 1

Views: 115

Answers (1)

keety
keety

Reputation: 17441

A simple approach would be to use multi-match query giving each field an appropriate boost.

{
    "query": {
        "multi_match": {
           "query": "produce",
           "fields": ["family^4","category^3","name^2","description"],
           "fuzziness" :  "AUTO",
           "rewrite" : "constant_score_auto"
        }
    }
}

All documents which match on the same field would get the same score. You can change this behavior by tweaking rewrite parameter Article gives further insight to this.

Upvotes: 1

Related Questions