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

Provide a way to convert QueryDescriptor to Query (Elastic.Clients.Elasticsearch, 8.11.0) #8016

Open
petr-horny-bsshop opened this issue Jan 23, 2024 · 2 comments
Labels
8.x Relates to 8.x client version Area: Generator Category: Feature

Comments

@petr-horny-bsshop
Copy link

Is your feature request related to a problem? Please describe.
There is ony single overload of FiltersAggregationDescriptor.Filter method which accepts Buckets<Query>:

public FiltersAggregationDescriptor<TDocument> Filters(Elastic.Clients.Elasticsearch.Aggregations.Buckets<Elastic.Clients.Elasticsearch.QueryDsl.Query>? filters)

This means that only Query can be used in the filter, not QueryDescriptor using FluentAPI.

What's worse is that we can't use FluentAPI in the whole path and we are stuck with Query object.

There is a related issue described here https://discuss.elastic.co/t/migrating-from-net-nest-client-to-v8-elastic-clients-elasticsearch-net-client/334959

Describe the solution you'd like
Provide a .ToQuery() conversion method

var queryDescriptor = new QueryDescriptor<Product>();
queryDescriptor.Term(p => p.Color, "red");

Query query = queryDescriptor.ToQuery();

OR

Create new overload for FiltersAggregationDescriptor.Filter

public FiltersAggregationDescriptor<TDocument> Filters(Elastic.Clients.Elasticsearch.Aggregations.Buckets<Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor<TDocument>? filters)

The former is preferred because it is more versatile.

Additional context
For now we used this workaround:

private Query ToQuery<TDocument>(QueryDescriptor<TDocument> queryDescriptor)
{
    using var ms = new MemoryStream();
    EsClient.RequestResponseSerializer.Serialize(queryDescriptor, ms, SerializationFormatting.Indented);

    ms.Position = 0;
    var query = EsClient.RequestResponseSerializer.Deserialize<Query>(ms);
    
    return query;
}
@CasperWSchmidt
Copy link

CasperWSchmidt commented Jan 26, 2024

Migrating from NEST to the new driver/client I have the same issues all over the place. In NEST query descriptors also implemented the corresponding query interface (e.g. BoolQueryDescriptor<T> : IBoolQuery).

In general, migrating from NEST is truly painful. There's no migration guide, no documentation/API reference for the .Net client, and close-to-no documentation on mouse-over in the IDE. You have to start guessing the new class names and go from there (usually decompiling the code and looking deeply into the various classes).

@flobernd flobernd added the 8.x Relates to 8.x client version label Jan 29, 2024
@flobernd
Copy link
Member

Hi @petr-horny-bsshop,

  1. A conversion or inheritance structure like in NEST (where the descriptors are derived from the request/data classes or implement the same interface) won't get implemented in version 8.x of the client. I will re-evaluate the current design for the 9.x release.
  2. Currently, unions are missing support for descriptors. This is the root cause that prevents an overload from being generated at this place (and many others). Implementing descriptor support for unions is on my todo list 🙂

@CasperWSchmidt

This fundamental design decision was taken before I inherited this project and for now I won't change this back. As stated above, I'll re-evaluate this design together with the former maintainers and try to improve usability for version 9.x.

There's no migration guide

https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/migration-guide.html

no documentation/API reference for the .Net client

This is on my very short term todo list. You can expect an auto-generated API reference to be available soon.

close-to-no documentation on mouse-over in the IDE

This should have changed with the new code generator and version 8.13.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version Area: Generator Category: Feature
Projects
None yet
Development

No branches or pull requests

3 participants