Draw Graphs on Aggregated View of Existing Index


I have to create a dashboard in a domain where there are orders and parcels. Right now there is an existing index named "parcels". To simplify my question, lets say that this index contains the "parcel_id", "order id" and a flag "is_big_parcel" and "order_date".

I have to create two visualizations

  1. show against time, the order count which contains "big_parcels".
  2. In a given time range, the order count which had 1 parcel, 2 parcels, 3 parcels.. etc

It seems to me that this can be achieved if I had an index "orders" with order_id, order_date, parcel_count, and order_has_big_parcel. But this is an aggregation on the already existing "parcels" index. Is it possible to create such a view based on existing "parcels" index? If not what would be the best way to achieve these visualizations?

Thanks in advance!

hi @pubudu,

for (1) you can probably just do a filter on the is_big_parcel field and do a "Unique Count" (aka cardinality) metric for a Date Histogram aggregation. You would do that unique count on the order_id field. There is some trade-offs involved in doing cardinality ranking in Elasticsearch wrt. precision, so check with the docs if that would work for you. (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html).

for (2) , I'm a little stumped on that. I don't see right away how you could do that with your current index structure. you basically want to count the number of parcels by order-id first, and then count the number of order-ids by that count. That's a two-step aggregation, and we do not expose this into Kibana as-is right now.

1 Like

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