Elasticsearch - count users query

Hi everyone,

I'm having a problem that I hope someone can help me with:

I have the next mapping for my user index -> docs(users) containing events
in which the user bought different products. each event(date) can contain
several products. I would like to retrieve the count of users that their
last purchase of TV was TOSHIBA. for that I am willing to have a 'TV' as a
product by itself.

So in case a have the next events:

user1|2013-05-18|TV,SAMSUNG
user1|2013-05-19|TV,TOSHIBA
user1|2013-05-20|PC
user2|2013-05-18|TV,TOSHIBA
user2|2013-05-19|TV,SAMSUNG
user2|2013-05-20|PC

user1 should be counted because its last bought TV was TOSHIBA but user2
should not.

Does anyone have an idea how to approach this query?

I tried several times but I'm new to elasticsearch so no success yet.

Thanks in advanced,

    {

"user" : {
"properties" : {
"name": {"type" : "string"},
"events" : {
"type" : "nested",
"properties" : {
"event_time" : {"type" : "Date"},
"products" : { "properties" : { "product" : {"type" : "string"} } }
}
}
}
}
}

--
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.