Hoang Le
Hoang Le

Reputation: 13

Elasticsearch combine multiple condition and sort by score

When searching document by title and I using sort by _score, the results are good and document matched with the search keyword.

But my document has the score of its own. and when I using multiple sorts ( qualityScore first and _score of elastics second). the results show qualityScore high first but title matched with search keyword not good.

how can I combine _score more than one condition?

Anyone have an idea please help me. Thank advance.

This is my query

GET member-recipes/_search
{
  "sort": [
    {
      "qualityScore": {
        "order": "desc"
      }
    },
    "_score"
  ],
    "query": {
      "bool": { 
       "must": [
          { "match": {"title": "21-Day-Fix-Instant-Pot-Chicken-Marsala-Stove-top-896247"}}
        ]
      }
    }
}

Upvotes: 1

Views: 1376

Answers (1)

NicolasY
NicolasY

Reputation: 323

You can use function_score search query with qualityScore as field_value_factor (for example with square as modifier)

GET /_search
 {
  "query": {
    "function_score": {
      "field_value_factor": {
        "field": "qualityScore",
        "factor": 1.2,
        "modifier": "sqrt",
        "missing": 1
      },
      "query": {
        "match": {
          "title": "21-Day-Fix-Instant-Pot-Chicken-Marsala-Stove-top-896247"
        }
      }
    }
  }
}

Upvotes: 1

Related Questions