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

Bool query operators seem to be missing from 8.0.0-beta.1 high level client API

Open sjg-ep opened this issue 1 year ago • 1 comments

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?

sjg-ep avatar Jul 15 '22 04:07 sjg-ep

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

stevejgordon avatar Jul 18 '22 07:07 stevejgordon

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

jonyadamit avatar Mar 13 '23 08:03 jonyadamit

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

lanwin avatar Mar 13 '23 08:03 lanwin

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?

svenhartmann avatar Mar 15 '23 10:03 svenhartmann

@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 avatar Mar 15 '23 13:03 stevejgordon

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

stevejgordon avatar Mar 15 '23 13:03 stevejgordon

@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?

svenhartmann avatar Mar 15 '23 14:03 svenhartmann

@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" } };

stevejgordon avatar Mar 15 '23 15:03 stevejgordon

@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);

svenhartmann avatar Mar 17 '23 09:03 svenhartmann

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 avatar Apr 06 '23 15:04 stevejgordon