Hi,
I'm using Elasticsearch JAVA DSL library with Version 5.6
I am trying to create an Elasticsearch Query that is similar to the one mentioned below.
{
"aggs": {
"aggName": {
"terms": {
"script": "Math.round((doc['field1'].value - doc['field2'].value)/640000)"
}
}
}
}
The way I am creating a Terms aggregate now is as follows.
TermsAggregationBuilder subAggregation = AggregationBuilders
.terms("aggName")
.script(new Script("Math.round((doc['field1'].value - doc['field2'].value)/640000)")
.size(0)
.order(Terms.Order.term(true));
However, the response for this aggregate Builder is as follows.
{
"aggs": {
"aggName": {
"terms": {
"script": {
"source": "Math.round((doc['field1'].value - doc['field2'].value)/640000)",
"lang": "painless"
}
}
}
}
}
And when the same query is run on Elasticsearch, I end up with the following Error.
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[terms] failed to parse field [script]",
"line": 7,
"col": 21
}
],
"type": "parsing_exception",
"reason": "[terms] failed to parse field [script]",
"line": 7,
"col": 21,
"caused_by": {
"type": "illegal_argument_exception",
"reason": "[script] unknown field [source], parser not found"
}
},
"status": 400
}
Can someone please direct me in the right way to generate the Expected JSON Structure that I want to use for querying the Elasticsearch using the JAVA SDK.