Count when element has field "tcode"

I would like a graph that only counts the elements that have the field "tcode".
I think I have to use JSON for it but I'm not sure maybe there is an easier way.
This is the JSON code I tried but it doesn't work (it still counts every element):
"query": {
"field": "tcode"

Greating Bert

Hi @bertvervaele,

you should be able to achieve that by using the "Count" aggregation in combination with a query like _exists_:tcode in the top query bar.

Thanks for the help! It does work when I do it like that .
But I'm look to make a graph with 2 Y-axis ( 1 with all elements and 1 with the elements that does have the tcode field.
So is there an other way then to use the filter?

I see - in that case you should be able to use the "Filters" aggregation with two filters to split the results into two buckets: * for all documents and _exists_:tcode for all documents that have the field.

You can also combine that with further aggregations, such as "Date Histogram".

1 Like

Thank you again this is exactly what I was looking for :slight_smile:

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