Skip to content

[FEATURE] Support bool query operators in Query DSL #6556

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

Closed
ghost opened this issue Jul 15, 2022 · 10 comments
Closed

[FEATURE] Support bool query operators in Query DSL #6556

ghost opened this issue Jul 15, 2022 · 10 comments
Labels
8.x Relates to a 8.x client version

Comments

@ghost
Copy link

ghost commented Jul 15, 2022

Elastic.Clients.Elasticsearch version:

8.0.0-beta.1

Elasticsearch version:

8.3.2

.NET runtime version:

6.0.300

Operating system version:

NixOS 22.05

Description of the problem including expected versus actual behavior:

The operators described on this page appear to be missing.
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/bool-queries.html

Expected behavior

I expected them to be provided, eventually. Unless for some reason they are no longer intended to be supported?

@ghost ghost added the 8.x Relates to a 8.x client version label Jul 15, 2022
@stevejgordon
Copy link
Contributor

Hi @sjg-ep. Operators for combining queries are currently a missing feature. The intention is to re-introduce these during the beta phase.

@stevejgordon stevejgordon changed the title Bool query operators seem to be missing from 8.0.0-beta.1 high level client API [FEATURE] Support bool query operators in Query DSL Dec 14, 2022
@jonyadamit
Copy link
Contributor

Has this been added yet? Is there an estimation for it's availability?

@lanwin
Copy link

lanwin commented Mar 13, 2023

I am also wonder when this will be available. We relay heavily on them and can not upgrade without it.

@svenhartmann
Copy link

Same issues here.

I'm also confused because a TermsQuery for example inherits from SearchQuery but the property Must of the BoolQuery expects an object of type Query.

Are there examples of how I can use multiple TermsQuery within Must/Should/... of a BoolQuery with the new client?

What is the proper way to convert a SearchQuery to a Query?

@stevejgordon
Copy link
Contributor

@svenhartmann The various query types have implicit conversion operators to Query, a container type. This test includes a basic example of building bool queries with either the object initializer or fluent syntax.

@stevejgordon
Copy link
Contributor

I don't have an ETA I can share for when this feature will be reintroduced.

@svenhartmann
Copy link

@stevejgordon Thanks for the fast anwser! I didn´t realized cast at static implicit operator Query(TermsQuery termsQuery). So it should be safe to use casting at array or list level e.g. aListOfTermsQuery.Cast<Query>().ToArray() , correct?

@stevejgordon
Copy link
Contributor

@svenhartmann No, you won't be able to the IEnumerable.Cast approach. Due to how that's implemented, it won't work with user-defined operators. Can you not type your original List to List<Query>? If not, you may need to Select and cast the elements manually.

var queries = new List<Query> { new TermQuery("a-field") { Value = "a-value" }, new TermQuery("a-field") { Value = "b-value" } };

@svenhartmann
Copy link

svenhartmann commented Mar 17, 2023

@stevejgordon Thanks for the hint. Did it like

var terms = filters
.Select(x =>
{
    return Query.Terms(new TermsQuery
    {
        Field = "myField", Terms = new TermsQueryField(x.Values.Select(FieldValue.String).ToArray())
    });
})
.ToArray();

and then created a simple BoolQuery with a Must clause. Works fine :)

With the NEST Client i used a list of terms queries and Enumerable.Aggregate to create the BoolQuery e.g. var boolQuery = terms.Aggregate(queryContainer, (current, item) => current & item);

@stevejgordon
Copy link
Contributor

I've broken this issue into two units of work which we will address separately. I'll close out this issue as we'll track progress in the new issues.

@stevejgordon stevejgordon closed this as not planned Won't fix, can't repro, duplicate, stale Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to a 8.x client version
Projects
None yet
Development

No branches or pull requests

4 participants