次のようなインデックスがあります。
[
{
"Name": "Alex",
"LastName": "Ich",
"Department": 2
},
{
"Name": "Charlie",
"LastName": "Sheen",
"Department": 3
},
{
"Name": "Peter",
"LastName": "Petrelli",
"Department": 5
},
{
"Name": "Alan",
"LastName": "Harper",
"Department": 6
},
{
"Name": "Ann",
"LastName": "Bottle",
"Department": 3
},
]
そして、 distinct で結果を取得したいのですが、Department
順序は気にせず、 ごとに 1 つの結果だけDepartment
です。集計を試してみましたが、関連付けられDeppartments
たdoc_countとの違いしか得られませんでした。彼らは私が試したクエリは次のようなものです:
{
"aggs": {
"deppartments": {
"terms": {
"field": "Department"
}
}
},"size": 0
}
戻り値:
"buckets": [
{
"key": 2,
"doc_count": 1
},
{
"key": 3,
"doc_count": 2
},
{
"key": 5,
"doc_count": 1
},
{
"key": 6,
"doc_count": 1
},
]
次のようなものが欲しいとき:
[
{
"Name": "Alex",
"LastName": "Ich",
"Department": 2
},
{
"Name": "Charlie",
"LastName": "Sheen",
"Department": 3
},
{
"Name": "Peter",
"LastName": "Petrelli",
"Department": 5
},
{
"Name": "Alan",
"LastName": "Harper",
"Department": 6
}
]