0
votes

I want to set a boosting for values in fields, while searching the following strings in elastic search

Index value

id title
1. stack installer
2. stack
3. stack material
4. installer

I searching those values using match query, then i got a following result

Query:

curl -XGET localhost:XXXX/index/type/_search?pretty -d '{"query":{"matchpharse":
     {"title":"stack installer"},
     "minimum_should_match":90
}'

Hit Result:

stack installer
installer
stack material
stack

But,I Need following order of output

stack installer
stack
stack material
installer
1

1 Answers

0
votes

In boolean should statement , you can give multiple queries of should and boost certain query over other.

curl -XGET localhost:XXXX/index/type/_search?pretty -d '{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "title": "installer stack",
            "boost": 3
          }
        },
        {
          "match": {
            "title": "installer",
            "boost": 2
          }
        },
        {
          "match": {
            "title": "stack",
            "boost": 1
          }
        }
      ]
    }
  }
}'