I have documents in elasticsearch that contains attributes like
{
[
{
"DTCREATED": "2016-09-19T18:30:00.000Z",
"amount ": 12
"SUBMERCHANTTRANSACTION" : -1
},
{
"DTCREATED": "2016-09-20T18:30:00.000Z",
"amount ": 30
"SUBMERCHANTTRANSACTION" : 0
},
{
"DTCREATED": "2016-10-25T18:30:00.000Z",
"amount ": 35
"SUBMERCHANTTRANSACTION" : -1
}
]
}
('-1' for yes '0' for no)
I want to get sum of all amount monthwise where SUBMERCHANTTRANSACTION is '-1' (Yes). I have tried below query
requestQuery =
Requests.searchRequest(ConstantsValue.indexName)
.types(ConstantsValue._Type)
.source("{size:999999,"
+ "\"_source\" : "
+ "[\"DTCREATED\", \"amount\"]"
+ ",\"filter\": "
+ "{\"terms\": {\"SUBMERCHANTTRANSACTION\": -1},"
+ "\"aggs\" : "
+ "{\"group_by_DATE\" : {\"date_histogram\" : "
+ "{\"field\" : \"DTCREATED\", \"interval\" : \"1M\","
+ "\"format\" : \"yyyy-MM\" },"
+ "\"aggs\" : "
+ "{\"intraday_return\" : { \"sum\" : { \"field\" : \"amount\" } }}}}}}}");
But it does not working. any idea what I am missing ?