i have 5 documents of index which having a array of topics , 2 of them documents having a duplication of array something like below
{
"_index": "testindex",
"_type": "testindex",
"_id": "125",
"_score": 1,
"_source": {
"topics": [
"Love",
"Entertainment"
]
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "126",
"_score": 1,
"_source": {
"topics": [
"Health",
"Fitness"
]
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "127",
"_score": 1,
"_source": {
"topics": [
"Health",
"Fitness"
]
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "128",
"_score": 1,
"_source": {
"topics": [
"Sports",
"Cricket"
],
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "129",
"_score": 1,
"_source": {
"topics": [
"Fit",
"gym"
],
}
}
here is my query of Elasticsearch
GET testindex/_search
{
"size":0,
"aggs": {
"topics": {
"terms": {
"field": "topics.keyword",
"size": 10
},
"aggs": {
"testindex": {
"top_hits": {
"size": 10
}
}
}
}
}
}
the result of my query is
"aggregations": {
"topics": {}
"buckets": [
{
"key": "health",
"doc_count": 2,
"testindex": {
"hits": {
"total": 2,
"max_score": 6.3823323,
"hits": [
{
"_index": "testindex",
"_type": "testindex",
"_id": "126",
"_score": 1,
"_source": {
"topics": [
"Health",
]
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "127",
"_score": 1,
"_source": {
"topics": [
"Health"
]
}
},
]
}
}
},
{
"key": "Fitness",
"doc_count": 2,
"testindex": {
"hits": {
"total": 2,
"max_score": 6.3823323,
"hits": [
{
"_index": "testindex",
"_type": "testindex",
"_id": "126",
"_score": 1,
"_source": {
"topics": [
"Fitness",
]
}
},
{
"_index": "testindex",
"_type": "testindex",
"_id": "127",
"_score": 1,
"_source": {
"topics": [
"Fitness"
]
}
},
]
}
}
},
]
}
}
Expectation is not duplication of bucket , i want single result of each index document ,
Thanks in advance