Show dynamic info from field names in a pie chart?

Hi,

I have a use-case which I can't seem to resolve.

I have in a document a map of animals, the key is the animal name, the values is an object with information on that animal, for example:

{
  "animals": {
    "cats": {
      "count": 8,
      "maxAge": 12,
      "minAge": 1
    },
    "elephants": {
      "count": 5,
      "maxAge": 120,
      "minAge": 30
    }
  }
}

Now, I want to aggregate all such documents, but because the name of the animal, is the field name, I don't know how to do it. For example:

  1. Piecharts of all animal names, where the slice size is the sum of counts of all that animal's entries.
  2. Table showing the animal name, min of min age, max of max age, sum of count

Hope the example is clear.

I have no problem with changing how this information is represented, BUT, it's important that a single document can hold the information on several animals, not just one animal at a time.

If I split a single document into multiple documents, one document for each animal, with a "animalName" field, the solution is clear and trivial. But do I HAVE to do it, because that's how ES/kibana works?

Thanks in advance,

Tal

Hi Tal,

I strongly recommend having multiple documents (one document for each animal). The indexing mechanism of Elasticsearch is designed to aggregate best across multiple documents.

1 Like

Thank you for the reply. That's what I feared. I'll change the structure.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.