0
votes

Currently, we have fixed 3 search queries in our multi-search query. The code looks like:

var results = elasticClient.MultiSearch(a => a
                           .Search<StockBaseEntity>(s => s
                           .Type("<docType>")
                           .Index(<indexName>)
                           .Take(<count>)
                           .Query(qq => qq
                           ...
                           .Search<StockBaseEntity>(s => s
                           .Type("<docType>")
                           .Index(<indexName>)
                           .Take(<count>)
                           .Query(qq => qq
                           ....
                           .Search<StockBaseEntity>(s => s
                           .Type("<docType>")
                           .Index(<indexName>)
                           .Take(<count>)
                           .Query(qq => qq
                           ....

All three search queries have some different query parameters, for example, first query returns "type1" doc, second & third return "type2 and type3" docs respectively.

We want to build this multi search nest query in such a way that we can have any number of search nest queries in multi searach query (and not only 3). It could be 3/4/5 or any number of search queries based on some condition. This can be achived if we can append search queries to multisearch? can we do this?

I read this article but can't get same for nest version 5.X and I have no clue how to write query with QueryContainer?

1
MultiSearchApiTests from NEST tests project should put some light on your question.Rob
I have done till this part. I have my queries in "fluent sytax". How do I put fluent query in "new QueryContainer()"? (as converting everything to OIS will take too much efforts)Sahil Sharma
@Rob: any idea? I have posted new question for this.. may be you will get some details at this link:- stackoverflow.com/questions/46999703/…Sahil Sharma

1 Answers

1
votes

One option is to use MultiSearchRequest and combine it with your search descriptors.

var multiSearchRequest = new MultiSearchRequest{};

multiSearchRequest.Operations = new Dictionary<string, ISearchRequest>();
multiSearchRequest.Operations["search1"] = new SearchDescriptor<object>().Query(q => q.MatchAll());
multiSearchRequest.Operations["search2"] = new SearchDescriptor<object>().Query(q => q.MatchAll());
multiSearchRequest.Operations["search3"] = new SearchDescriptor<object>().Query(q => q.MatchAll());

elasticClient.MultiSearch(multiSearchRequest);

Hope that helps.