michael lother
michael lother

Reputation: 139

Score based on string in elasticsearch

I have a field say "testField", where in there can be numerous string values like. I need to boost the score whenever the value in the field is a particular string,say for example "testValue". How can I do this in elasticsearch?

Upvotes: 1

Views: 61

Answers (1)

Andrei Stefan
Andrei Stefan

Reputation: 52368

You can try using function_score:

{
  "query": {
    "function_score": {
      "query": {
        "match_all": {}
      },
      "functions": [
        {
          "filter": {
            "term": {
              "testField": "testValue"
            }
          },
          "boost_factor": 15
        }
      ]
    }
  }
}

Upvotes: 2

Related Questions