I need to make some calculation with each doc's some fields and then return it as response's part I've written this
TermsAggregationBuilder subAggregation = AggregationBuilders
.terms("price")
.script(new Script(ScriptType.INLINE, "painless",
" int total = 0;\n" +
" for (int i = 0; i < 5; ++i) {\n" +
" total += doc['age'].value;\n" +
" }\n" +
" return total ;\n"
, Collections.emptyMap()));
NativeSearchQuery nativeSearchQuery = new NativeSearchQueryBuilder()
.withQuery(matchAllQuery())
.addAggregation(subAggregation)
.build();
SearchHits<Stories>
searchHits = elasticsearchOperations.search(nativeSearchQuery, Stories.class
, IndexCoordinates.of("long_stories"));
and this returns this one
{
"totalHits": 1,
"totalHitsRelation": "EQUAL_TO",
"maxScore": 1,
"scrollId": null,
"searchHits": [
{
"id": "44",
"score": 1,
"sortValues": [],
"content": {
"id": "44",
"innerId": 5,
"age": 44,
"salary": 433,
"mark": 10,
"state": "state",
"stores": [
{
"storiesId": "44",
"innerId": 1
},
{
"storiesId": "44b",
"innerId": 2
},
{
"storiesId": "44c",
"innerId": 3
}
],
"esh": null
},
"highlightFields": {}
}
],
"aggregations": {
"asMap": {
"price": {
"name": "price",
"metadata": null,
"buckets": [
{
"aggregations": {
"asMap": {},
"fragment": true
},
"keyAsString": "220",
"docCount": 1,
"docCountError": 0,
"key": "220",
"keyAsNumber": 220,
"fragment": true
}
],
"type": "sterms",
"docCountError": 0,
"sumOfOtherDocCounts": 0,
"fragment": true
}
},
"fragment": true
},
"empty": false
}
this response gives separate calculation I need it to be with above part ,and also if key which is 220 now if I had some another doc which would give the same answer then response would print 220 and doc count 2 I need it to be separately and in above response like doc1 220 doc2 220 and in above response where actual data holds