Hi!
My mapping is:
PUT /test
{
"mappings": {
"properties": {
"lufi": {
"properties": {
"duma": {
"type": "keyword"
}
}
}
}
}
}
Insert some data:
POST /test/_doc/777
{
"lufi": [
{
"duma": "aaa"
},
{
"duma": "aaa bbb"
},
{
"duma": "ccc"
}
]
}
Search for documents which 'duma' fields contains 'aaa', and I'd like to return the number of hits in the 'duma' fields:
POST /test/_search
{
"query": {
"match": {
"lufi.duma": "aaa"
}
},
"script_fields": {
"cnt": {
"script": {
"lang": "painless",
"source": "doc['lufi.duma'].size()"
}
}
}
}
The result is:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.39556286,
"hits": [
{
"_index": "test",
"_type": "_doc",
"_id": "777",
"_score": 0.39556286,
"_source": [],
"fields": {
"cnt": [
3
]
}
}
]
}
}
My problem is, the 'cnt' field contains 3, number of all 'duma' fields, but I need only the hits number, which is 2, because two duma fields ('aaa' and 'aaa bbb') values contains 'aaa', 'ccc' not. How can I solve this?
Thank you!