I’m migrating an API codebase from the .net v7.* Nest client to the newer v8 .net client
The API codebase using the Nest client makes frequent use of QueryDescriptors with logic operators that derive QueryContainer objects (a QueryContainer object can be used directly by the SearchAsync method on the Nest client). In the new client there is no QueryContainer type and the logic operators are not implemented for QueryDescriptor. So I've rewritten these queries, still using descriptors and fluent style, but now using the fluent methods for bool logic instead of the logic operators. The QueryDescriptor object gets passed all the way up to the client and gets set on the SearchRequestDescriptor used by the new client SearchAsync method.
This is fine for our API endpoint that runs single queries against Elasticsearch. However, the API also has an endpoint for multi searches. The multi search endpoint builds the query for each search in the same way as the single query endpoint so the query building code is shared between the two endpoints. For multi search this code builds a QueryDescriptor object for each search to be passed to the MultiSearchAsync method on the elasticsearch client. MultiSearchAsync takes a MultiSearchRequestDescriptor which has an AddSearch() method that takes a SearchRequestItem that takes a MultiSearchBody. MultiSearchBody has a Query property that takes a Query object, but not a QueryDescriptor object. So it seems it’s not possible to use the QueryDescriptor on the MultiSearchAsync client method.
So far I haven't found a way around this and feel I must be missing something obvious. It looks like, on the Java elasticsearch client, there is a ‘ToQuery()’ method on the descriptor to convert from QueryDescriptor to Query, but I can’t find an equivalent on the .net client.
If QueryDescriptors can’t be used with MultiSearchAsync that would mean the query building code in our API would have to be rewritten in non-fluent style to produce a Query object that can be used by MultSearchAsync(). As this would be a big job I’m looking for possible workarounds. Is there an easier way to achieve this call to MultiSearch using the fluent style to build the query?