2016-11-07 47 views
0

我有Elasticsearch產生的搜索結果如下:返回與獨特的標題頂部的搜索結果中Elasticsearch

查詢:蘋果派

1. title: apple pie, score: 144.67503 
2. title: apple pie, score: 128.19138 
3. title: apple, score: 59.768208 
4. title: apple, score: 39.49909 
5. title: red apple, score: 34.314064 
6. title: apple red, score: 34.014064 

我想有以下幾點:

1. title: apple pie, score: 144.67503 
2. title: apple, score: 59.768208 
3. title: red apple, score: 34.314064 
4. title: apple red, score: 34.014064 

我如何在Elasticsearch中做到這一點?如果在DSL中獲得響應將會很好。

回答

0
{ 
    "size": 0, 
    "query": { 
     "term": { 
     "title": { 
      "value": "apple pie" 
     } 
     } 
    }, 
    "aggs": { 
     "titleAgg": { 
     "terms": { 
      "field": "title", 
      "order": { 
       "scoreAgg": "desc" 
      } 
     }, 
     "aggs": { 
      "scoreAgg": { 
       "max": { 
        "script": "_score" 
       } 
      } 
     } 
     } 
    } 
} 

該查詢要給你們稱號關鍵下scoreAgg聚集比分爲

+0

我不知道,我怎麼能在管道中添加此聚集查詢,其中,通過function_score產生比分。 – misbah