I'm working in a small personal project that requires to make some queries in ElasticSearch, and I wanted to ask you for some advise because I'm kind of stuck.
This is the issue: So far I have a index that contains a type called users. It stores an email and array of events done by that user.
{
{
email : account1@gmail.com
events : [
{
type: 'SOLVE PROBLEM'
date : 20160402
},
{
type: 'RESPOND QUESTION'
date : 20160402
},
{
type: 'ASK QUESTION'
date : 20160403
},
{
type: 'SOLVE PROBLEM'
date : 20160509
},
{
type: 'ASK QUESTION'
date : 20160402
},
...
],
},
{
email : account2@gmail.com
events : [
{
type: 'RESPOND QUESTION'
date : 20160402
},
{
type: 'RESPOND QUESTION'
date : 20160402
},
{
type: 'ASK QUESTION'
date : 20160402
},
{
type: 'SOLVE PROBLEM'
date : 20160402
},
{
type: 'ASK QUESTION'
date : 20160402
},
...
],
},
-....
}
.....
I'd like to make queries based in the number of events done by each user, something like:
- Return me all the users(documents) that have "responded" more than 5 questions
- Return all the users that have "solved" 4 problems during 2016-01-01 and 2016-02-04
- Return all the users that have asked less than 4 questions
- Return me all the users(documents) that have "responded" more than 5 questions AND that have "solved" 4 problems during 2016-01-01 and 2016-02-04
The values come from a facet.
I'd like to ask you if you can give me some advice about which filter/aggs do I need to use in order to filter a document based in the number of elements in a subdocument.
Because I have been reading about how make it but I have not been able do to do it yet, and even worst, I'm not sure if it is possible, because I read that ES doesn't have a HAVING clause like in SQL
Thank you for any help or advice.