我想通過字段進行搜索了一些成果和其他領域(「myScore的」),對它們進行排序獲得不同的記錄,這裏是ES(5.2.2)查詢:Elasticsearch:由某一特定領域
{
"sort": [
{"myscore": {"order" :"desc"}}
],
"query": {
"query_string" : {
"query" : "(field1:foo) AND (field2:bar)"
}
}
}
那麼,我能得到這個:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "fooindex",
"_type": "footype",
"_id": "1",
"_score": null,
"_source": {
"field1": "foo",
"field2": "bar",
"x_id": "x001",
"myscore": 0.9
},
"sort": [
0.9
]
},
{
"_index": "fooindex",
"_type": "footype",
"_id": "2",
"_score": null,
"_source": {
"field1": "foo",
"field2": "bar",
"x_id": "x001",
"myscore": 0.8
},
"sort": [
0.8
]
},
{
"_index": "fooindex",
"_type": "footype",
"_id": "3",
"_score": null,
"_source": {
"field1": "foo",
"field2": "bar",
"x_id": "x002",
"myscore": 0.7
},
"sort": [
0.7
]
}
]
}
}
但是,我想根據現場得到不同的結果 「X_ID」,像這樣:
{
"_index": "fooindex",
"_type": "footype",
"_id": "1",
"_score": null,
"_source": {
"field1": "foo",
"field2": "bar",
"x_id": "x001",
"myscore": 0.9
},
"sort": [
0.9
]
},
{
"_index": "fooindex",
"_type": "footype",
"_id": "3",
"_score": null,
"_source": {
"field1": "foo",
"field2": "bar",
"x_id": "x002",
"myscore": 0.7
},
"sort": [
0.7
]
}
類似的SQL將是「從腳步羣組中選擇* x_id」;
我試過聚集:
"aggs": {
"unique_xid": {
"terms": {
"field": "x_id"
}
}
},
其結果將是:
"aggregations": {
"unique_ids": {
"buckets": [
{
"key": "x001",
"doc_count": 2
},
{
"key": "x002",
"doc_count": 1
}
]
}
}
的問題是,聚集的結果泄漏現場的信息和他們排序「算」不「將myScore 」。有什麼方法可以通過指定字段獲得不同的結果嗎?
在你的' x001'桶你意識到有兩個文件,對吧?那麼應該將哪個「myscore」考慮在內以對桶進行分類?最大的一個? – Val
@Val是的,最大的一個。 – user7783308