2017-03-12 62 views
0

我有一個名爲find的索引和一個名爲song的類型。 宋式結構:Elasticsearch增強

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

2兩說不定之間索引首歌,一首歌有一點點的最好成績,而另一首歌曲是最流行的用戶之間,有更多的下載量。我需要通過分數與downloadCount字段值的組合對結果進行排名。 – Mehmed

回答

0

推動的結果,你可以使用function score查詢。功能得分查詢提供了基於文檔字段通過script_score函數對文檔打分的API。

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

感謝