0

我有一个名为的索引find和一个名为song. 歌曲类型结构:

    "_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
    }

由于多首歌曲可能具有相同的字段值,所以我需要通过诸如 downloadCount 之类的流行字段来提升结果。

如何更改以下查询以通过 downloadCount 进行优化?

GET /search/song/_search
{
  "query": {
      "multi_match": {
          "query": "like a dead hangs",
          "type": "most_fields",
          "fields": ["artist","title","lyrics"],
          "operator": "or"
        }
     }
}
4

2 回答 2

0

您可以使用功能分数查询。函数评分查询通过script_score函数提供了基于文档字段对文档进行评分的api 。

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

谢谢

于 2017-03-13T05:29:21.163 回答
0

您可以使用field_value_factorelastic_search 的功能来提升结果downloadCount

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

于 2017-03-12T10:49:47.367 回答