Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing filter aggregation #912

Open
ixixix-001 opened this issue Nov 23, 2024 · 2 comments
Open

Missing filter aggregation #912

ixixix-001 opened this issue Nov 23, 2024 · 2 comments
Labels
Area: Specification Related to the API spec used to generate client code Category: Question Not an issue but a question. May lead to enhancing docs

Comments

@ixixix-001
Copy link

ixixix-001 commented Nov 23, 2024

Java API client version

8.15.2

Java version

21

Elasticsearch Version

8.15.2

Problem description

Hi, there is no way to define a filter aggregation (not "filters").

Seems the class "FilterAggregation" is not generated at all.
And: The code for method "filter()" in class "Aggregation" returns a Query object instead of an aggregation variant.

public Query filter() { return TaggedUnionUtils.get(this, Kind.Filter); }

Was this an intentional decision to implement it this way (as a Query-Object) ?
Otherwise it would be nice to add the class "Filteraggregation" in the generator and change the return types from Query to "FilterAggregation".

@l-trotta
Copy link
Contributor

l-trotta commented Nov 25, 2024

Hello, thanks for the report! I think this is correct, filter in an aggregation is none other than a query that can be used to filter the result of the aggregation, as the documentation states:

A single bucket aggregation that narrows the set of documents to those that match a query.

@l-trotta
Copy link
Contributor

So to translate the example used in the documentation in java dsl:

POST /sales/_search?size=0&filter_path=aggregations
{
  "aggs": {
    "avg_price": { "avg": { "field": "price" } },
    "t_shirts": {
      "filter": { "term": { "type": "t-shirt" } },
      "aggs": {
        "avg_price": { "avg": { "field": "price" } }
      }
    }
  }
}
esClient.search(s -> s
        .aggregations(Map.of("t_shirts", Aggregation.of(a -> a
            .filter(f -> f
                .term(t -> t
                    .field("type")
                    .value(FieldValue.of("t-shirt"))
                ))
                .aggregations("avg_price", ag -> ag
                    .avg(av -> av
                        .field("price")
                    )
                )
            ), "avg_price", Aggregation.of(agg -> agg
            .avg(av -> av
                .field("price")
            ))))
        .index("sales")
        .size(0)
    , Void.class);

@l-trotta l-trotta added Area: Specification Related to the API spec used to generate client code Category: Question Not an issue but a question. May lead to enhancing docs labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Specification Related to the API spec used to generate client code Category: Question Not an issue but a question. May lead to enhancing docs
Projects
None yet
Development

No branches or pull requests

2 participants