elasticsearch-java icon indicating copy to clipboard operation
elasticsearch-java copied to clipboard

bucket script unknown field 'name' error.

Open Mert18 opened this issue 1 year ago • 0 comments

Java API client version

8.6.0

Java version

11

Elasticsearch Version

7.14.0

Problem description

I am trying to create a bucket script aggregation, filling the 'name' field as it is included in the builder.

Aggregation bucketScriptAggregation = Aggregation.of(a -> a.bucketScript(b -> b.script(script).bucketsPath(p -> p.array(bucketsPaths)).name(aggName)));

This is one of the aggregations, the method returns List< Aggregation > .

Then I include this aggregation into my search request:

kpiAgg.putAll(kpiBucketAggregations.stream().collect(Collectors.toMap(
                aggregation -> aggregation.bucketScript().name(),
                aggregation -> aggregation
        )));
...
// Added kpiAgg to parent "aggregationMap".
...
SearchRequest searchRequest = SearchRequest.of(s -> s
                    .index(indexes)
                    .query(boolQuery._toQuery())
                    .aggregations(aggregationMap)
            );

When sending the search request, the following error is thrown:

co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [x_content_parse_exception] [1:534] [bucket_script] unknown field [name]

ErrorResponse: {"error":{"type":"x_content_parse_exception","reason":"[1:534] [bucket_script] unknown field [name]","root_cause":[{"type":"x_content_parse_exception","reason":"[1:534] [bucket_script] unknown field [name]"}]},"status":400}

Is that a bug or am I using it incorrectly? Thanks in advance.

Mert18 avatar Oct 20 '23 07:10 Mert18