How to calculate facet over parent documents?

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
-d'{"name":"A","color":"blue","weight":3}'
curl -XPUT localhost:9200/test/item/2
-d'{"name":"B","color":"red","weight":6}'
curl -XPUT localhost:9200/test/item/3
-d'{"name":"C","color":"blue","weight":3}'
curl -XPUT localhost:9200/test/item/4
-d'{"name":"D","color":"green","weight":2}'

curl -XPOST localhost:9200/test/event/_mapping
-d'{"event":{"_parent":{"type":"item"}}}'

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
(15/4=3.75)?
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 elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.