I have an elastic search index for firms that has a nested object called transactions . There is at least a date in the transaction . Here is an example:
firms: [
{
"name": "abc",
"address" : "xyz",
"transactions": [
{
"date" : "2014-12-20"
"side" : "buyer"
},
...
]
},
...
]
Given this data, I want to request from all firms that have (say) 3+ transactions in the last 6 or 12 months.
The following query returns firms that have at least one transaction in the last 12 months:
POST firms/firm/_search
{
"query": {
"nested": {
"path": "transactions",
"query": {
"bool": {
"must": [
{
"match": {
"transactions.side": "buyer"
}
},
{
"range": {
"transactions.date": {
"from": "2014-10-24",
"to": "2015-10-24"
}
}
}
]
}
}
}
}
}
I am not sure how to expand this query to fit firms with x + transactions in the y + month period. Any help would be appreciated. Thanks
source
share