How to calculate facet over parent documents?

(joerg.reichardt) #1

Hi all,

I'd like to calculate the statistics of an event stream in which only a
limited number of possible events occur. I've modeled this as an item type
with some properties, and an event type that has an item as parent and only
stores the time of the event. The number of items (possible events) is
much, much smaller than the number of events.

I'd now like to calculate statistics for the events. Consider the following
example: 4 items and 7 events

curl -XPUT localhost:9200/test/item/1
curl -XPUT localhost:9200/test/item/2
curl -XPUT localhost:9200/test/item/3
curl -XPUT localhost:9200/test/item/4

curl -XPOST localhost:9200/test/event/_mapping

curl -XPOST localhost:9200/test/event?parent=1 -d'{"day":"Mon"}'
curl -XPOST localhost:9200/test/event?parent=2 -d'{"day":"Mon"}'
curl -XPOST localhost:9200/test/event?parent=3 -d'{"day":"Mon"}'
curl -XPOST localhost:9200/test/event?parent=3 -d'{"day":"Mon"}'
curl -XPOST localhost:9200/test/event?parent=4 -d'{"day":"Tue"}'
curl -XPOST localhost:9200/test/event?parent=1 -d'{"day":"Tue"}'
curl -XPOST localhost:9200/test/event?parent=1 -d'{"day":"Tue"}'

How can I calculate the average weight for all events occurring on Monday
More general, I'd like to be able to filter the events by day and then
calculate a (statistial) facet of item properties over these events.

I know I could repeat the item data in each event and the problem would be
solved, i.e. for each incoming event, query the item properties and
replicate them again, but that would require one read of an item for ever
write of an event plus require to re-index an item with every event. That
appears to be silly.

Any help is greatly appreciated!

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

(system) #2