0
votes

I am trying to use elastic low level client to search multiple indices through -

client.LowLevel.Search(PostData.Serializable(new SearchRequest(new[] {"Index1", "Index2"}) { Size = 10, From = 0, Query = searchQuery))

Results i am getting are across other indices as well which i have not defined in the list of indices to search.

I found a work around -

client.LowLevel.Search("Index", PostData.Serializable(new SearchRequest() { Size = 10, From = 0, Query = searchQuery))

But this way i am not able to search multiple indices.

I also cant use the high level client since i want to return raw search response (without deserializing) which i have only been able to achieve through low level client.

1
Did you try to serialize your request to string to check if it is generation correct query or not? you can use elastic client RequestResponseSerializer.SerializeToString([query]) to do it. - Kaveh
Request is generating the exact query i want. But i can see the url its trying to hit is /_search which should ideally be /indexName/_search so basically it is ignoring indices passed as arguments to search request - Sahil Chawla
you should be able to use client.LowLevel.Search("Index", PostData.Serializable(new SearchRequest() { Size = 10, From = 0, Query = searchQuery)) and use a comma-separated list of index names to search; use the special string _all - Kaveh

1 Answers

0
votes

As you can check Elastic nest client documentation you can pass a comma-separated list of index names to search.

TResponse Search<TResponse>(string index, PostData body, SearchRequestParameters requestParameters = null) where TResponse : class, IElasticsearchResponse, new();

So your index string should be like "index1,index2".