I have below document structure.
{"tagsData": [
{
"hashtag": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
},
{
"hashtag": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
}
]}
My requirement is to apply aggregation on hashtag field and get the result like below
{"aggregations": {
"tags": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
"doc_count": 1
},
{
"key": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
"doc_count": 1
}]}
}}
Elasticsearch version 5.3 Please let me know know how can I achieve this? What should be the mapping and query?
EDIT
Mapping that I am trying.
{
"test": {
"properties" : {
"tagsData" : {
"type" : "object",
"properties": {
"hashtag" : {"type": "keyword", "index": "not_analyzed"},
"displayName" : {"type": "keyword", "index": "not_analyzed"},
"urlKeyword" : {"type": "keyword", "index": "not_analyzed"}
}
}
}
}
}