For the sake of easier understanding, I will show you how my data is mapped. Here is the template I'm having.
{
"mappings":
{
"properties":
{
"applicationName":
{
"type": "keyword"
},
"tags":
{
"type": "nested",
"properties":
{
"tagKey":
{
"type": "keyword"
},
"tagKeyword":
{
"type": "keyword"
}
}
}
}
}
}
Here are some sample items,
Sample item 1
"applicationName": "application1"
"tags": [
{"tagKey": "user", "tagKeyword": "aaa"},
{"tagKey": "os", "tagKeyword": "android"}
]
Sample item 2
"applicationName": "application2"
"tags": [
{"tagKey": "user", "tagKeyword": "bbb"},
{"tagKey": "os", "tagKeyword": "ios"}
]
Sample item 3
"applicationName": "application1"
"tags": [
{"tagKey": "user", "tagKeyword": "aaa"},
{"tagKey": "os", "tagKeyword": "pc"}
]
I want to retrieve the count of distinct tagKeyword that has tagKey of "user" for each application.
For example,
[
{
"applicationName": "application1",
"distinctUser": 2
},
{
"applicationName": "application2",
"distinctUser": 1
}
]
Both solution or URL to the document related to this issue will be appreciated.