Elasticsearch Aggregation on Array of Objects with same properties in result

时间:2018-11-13 07:54:46

标签: elasticsearch elasticsearch-5

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"}
        }
      }
    }
  }
}

0 个答案:

没有答案