Skip to content

Aggregation classes contain invalid field name #466

Closed
@EgbertW

Description

@EgbertW

Java API client version

7.17.7

Java version

11

Elasticsearch Version

7.17.7

Problem description

Problem Description

Aggregation classes contain an invalid field name. The server documentation doesn't list it but the aggregation base class at https://github.com/elastic/elasticsearch-specification/blob/7.17/specification/_types/aggregations/Aggregation.ts#L24 does list it, so it is present in all aggregations inheriting from it. The same problem seems to still be present in version 8.5 of the library.

If you use the field, the generated query is refused by the server with an error message:

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

Steps to reproduce:

SearchRequest searchRequest = SearchRequest.of(b ->
    b.aggregations("foobar", builder -> builder
        .terms(termsBuilder -> termsBuilder
            .field("testField")
            .name("testName")
        )
    )
);
elasticsearchClient.search(searchRequest, String.class);

This is especially confusing when migrating from the old RestHighLevelClient because the builder in that package at org.elasticsearch.search.aggregations.AggregationBuilders#terms accepts a name and actually uses it in properly in the resulting request.

Proposed resolution:

As the name isn't part of the Aggregation but on the containing object, it has no place within. Therefore, the aggregation and subclasses should not contain the name field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: SpecificationRelated to the API spec used to generate client code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions