Bar chart - Aggregate by Field1 or Field2

Hello,
I have documents with 2 fields that I would like to use for aggregation.
The document will look something like


"_source" : {
          "name" : "name_value",
          "id" : "id_value",
         ...
		 ...
        }

But, some names might be missing/empty.

I would like to show a bar chart (For example) that shows count by name, but if the name is empty present the id instead.

Is this possible? How?
If not, any alternatives?

Thanks!

Hey @AClerk,

Take a look at Scripted Fields. I believe these will do what you want. You can do aggregations on them as well.

Note that these are computed on-the-fly, and are potentially more resource-intensive. The better option, if you can do it, is to add another field to the record at index time that contains the correct value. That way, it's already there and indexed by Elasticsearch.

Brian

1 Like

Hi @brianseeders
Thanks for your reply.
I am aware of this solution but thought maybe there is a better way to do this.
Cheers!

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