I have the following query:
"query": {
"nested": {
"path": "cuccok",
"inner_hits": {},
"query": {
"bool": {
"must": [
{
"terms": {
"cuccok.point": [
1,
2
]
}
},
{
"terms": {
"cuccok.tag": [
3,
4
]
}
}
]
}
}
}
}
}
The result is:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 2,
"hits": [
{
"_index": "cucc",
"_id": "IkREdogBdZE48qyFJ4QS",
"_score": 2,
"_source": {
"itemid": 1,
"cuccok": [
{
"point": 1,
"tag": 3
},
{
"point": 2,
"tag": 4
}
]
},
"inner_hits": {
"cuccok": {
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 2,
"hits": [
{
"_index": "cucc",
"_id": "IkREdogBdZE48qyFJ4QS",
"_nested": {
"field": "cuccok",
"offset": 0
},
"_score": 2,
"_source": {
"point": 1,
"tag": 3
}
},
{
"_index": "cucc",
"_id": "IkREdogBdZE48qyFJ4QS",
"_nested": {
"field": "cuccok",
"offset": 1
},
"_score": 2,
"_source": {
"point": 2,
"tag": 4
}
}
]
}
}
}
},
{
"_index": "cucc",
"_id": "I0REdogBdZE48qyFJ4Qf",
"_score": 2,
"_source": {
"itemid": 2,
"cuccok": [
{
"point": 1,
"tag": 3
},
{
"point": 2,
"tag": 5
}
]
},
"inner_hits": {
"cuccok": {
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 2,
"hits": [
{
"_index": "cucc",
"_id": "I0REdogBdZE48qyFJ4Qf",
"_nested": {
"field": "cuccok",
"offset": 0
},
"_score": 2,
"_source": {
"point": 1,
"tag": 3
}
}
]
}
}
}
}
]
}
}
I'd like to return only the first (itemid = 1) doc, where the nested query inner_hits count = 2:
"inner_hits": {
"cuccok": {
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
How can I implement this?