Home > Software engineering >  Is there a way to add function_score even if query score is 0, ElasticSearch
Is there a way to add function_score even if query score is 0, ElasticSearch

Time:01-18

i have query like

{
  "explain": true,
  "query": {
    "bool": {
      "should": {
        "function_score": {
          "functions": [
            {
              "gauss": {},
              "weight": 10
            },
            {
              "filter": {},
              "weight": 5
            }
          ],
          "score_mode": "sum",
          "query": {
            "match": {
              "locality": {
                "query": "whitefield Mall"
              }
            }
          },
          "boost_mode": "sum",
          "boost": "30"
        }
      }
    }
  },
  "size": 1
}

for result whose query score is 0 its overall score becomes 0 even though if it has some function score. How do i avoid this.

What i want is to have the _score as the sum of function score and the query score, even if the query score is 0

Have tried playing with other boost_mode, but did not work

CodePudding user response:

One way is to put the query and the function in a different function_score

{
  "explain": true,
  "query": {
    "bool": {
      "should": {
        "function_score": {
          "functions": [
            {
              "gauss": {},
              "weight": 10
            },
            {
              "filter": {},
              "weight": 5
            }
          ],
          "score_mode": "sum",
          "query": {
            "match": {
              "locality": {
                "query": "whitefield Mall"
              }
            }
          },
          "boost_mode": "sum",
          "boost": "30"
        }
      }
    }
  },
  "size": 1
}
  • Related