With ElasticSearch, I would like to get the sum of a field for a period with filtering on a value of an other field.
I defined this mapping:
PUT match-orders
{
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
},
"mappings": {
"order": {
"_all": {"enabled": false},
"properties": {
"matchTime": {"type": "date", "index": "true"},
"product_id": {"type": "keyword", "index": "true"},
"size": {"type": "float", "index": "true"},
"price": {"type": "float", "index": "true"},
"side": {"type": "keyword", "index": "true"}
}
}
}
}
I can get the sum for a range:
POST /match-orders/_search?pretty
{
"aggs" : {
"price_ranges" : {
"range" : {
"field" : "matchTime",
"ranges" : [
{ "from" : "2017-09-10T18:00:00Z", "to" : "2017-09-10T18:15:00Z" }
]
},
"aggs" : {
"result" : { "sum" : { "field" : "size" } }
}
}
}
}
I can get the documents which contain a specific term:
POST /match-orders/_search?pretty
{
"query": {
"term" : { "side" : "sell" }
}
}
But how can I combine these two queries?
Thank you :)