0

I have an index called find and a type called song. Song type structure :

    "_index": "find",
    "_type": "song",
    "_id": "192108",
    "_source": {
      "id": 192108,          
      "artist": "Melanie",
      "title": "Dark Night",
      "lyrics": "Hot air hangs like a dead man\nFrom a white oak tree",
      "downloadCount": 234
    }

Because of multiple songs maybe has same field values, so I need to boost results by a popularity field such as downloadCount.

How can i change below query to optimize by downloadCount?

GET /search/song/_search
{
  "query": {
      "multi_match": {
          "query": "like a dead hangs",
          "type": "most_fields",
          "fields": ["artist","title","lyrics"],
          "operator": "or"
        }
     }
}
sehe
  • 374,641
  • 47
  • 450
  • 633
Mehmed
  • 9
  • 1
  • 4
  • maybe between two indexed song, a song has a little bit best score, but another song was most popular between users and has more downloads. I need to rank results by a combination between score and downloadCount field value. – Mehmed Mar 12 '17 at 09:55

2 Answers2

0

You can use field_value_factor feature of elastic_search to boost the result by downloadCount

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor

saurabh
  • 110
  • 3
  • 12
0

you can use function score query. Function score query provides api for scoring the document based on the document field through script_score functions.

{
    "query": {
        "function_score": {
            "query": {
                "bool": {
                    "must": [{
                        "term": {
                            "you_filter_field": {
                                "value": "VALUE"
                            }
                        }
                    }]
                }
            },
            "functions": [{
                "script_score": {
                    "script": "doc['downloadCount'].value"
                }
            }]
        }
    }
}

Thanks

user3775217
  • 4,675
  • 1
  • 22
  • 33