Elastic Search Aggregation query parameter to visualize bar chart

364 views Asked by At

So I want to create a bar chart to display all the "name" fields of all the animal groups in the x-axis and its total "value" field in the y-axis(or vice-versa) from now to 6 months before. What will the query parameter be for this? Couldn't seem to visualize this in Kibana either: the "AnimalGroup" field wasn't available to select.

The data structure is as follows:

"hits" : [
      {
       "_source" : {
           "AnimalGroup":[
             {
                "value": 12,
                "name": cat
              },
             {
                "value": 13,
                "name": dog
             },
           ],
      {
        "_source":{
          "AnimalGroup":[
             {
                "value": 12,
                "name": fish
              },
             {
                "value": 50,
                "name": dog
             },
           ]
        } 
     }
]

Mapping:

"mappings" : {
      "dynamic_templates" : [ ],
      "properties" : {
        "AnimalGroup" : {
          "properties" : {
            "value" : {
              "type" : "long"
            },
            "name" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
}

EDIT: Added the mapping of the data.

1

There are 1 answers

2
Sagar Patel On

You need to select sum aggregation on Y-axis and select AnimalGroup.value as field.

You need to select Terms aggregation on X-axis and select AnimalGroup.name.keyword as field.

Y-axis

enter image description here

X-axis

enter image description here

Graph

enter image description here