elasticsearch-net
elasticsearch-net copied to clipboard
Bool query operators seem to be missing from 8.0.0-beta.1 high level client API
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?
Hi @sjg-ep. Operators for combining queries are currently a missing feature. The intention is to re-introduce these during the beta phase.
Has this been added yet? Is there an estimation for it's availability?
I am also wonder when this will be available. We relay heavily on them and can not upgrade without it.
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 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.
I don't have an ETA I can share for when this feature will be reintroduced.
@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 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 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);
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.