Scott
Scott

Reputation: 442

ElasticSearch NEST - Using client.Get to get search for a document across all indexes

Using NEST v6.4.2

I need to use the client.Get API to fetch a document which searches across ALL indices instead of one index.

My code looks as follows:

   var client = // intiialize elasticsearch client here
   var id = // some document id

   // the call to client.Get below fails as "" is not a valid index name
   // I have also tried passing "*", Indicies.All, Indices.AllIndices, etc but nothing works

   var document = client.Get<dynamic>(new GetRequest("", "_all", id));

Has anyone done this before? Documentation seems to show that you can do this using the client.Search API but this is not optimal for retrieving a single document so I would like to avoid if possible.

Thanks

Upvotes: 0

Views: 1449

Answers (1)

Rob
Rob

Reputation: 9979

From docs for elasticsearch 6.x

Single index APIs such as the Document APIs and the single-index alias APIs do not support multiple indices.

but you can do term query on _id field to retrieve documents based on id

var response = await client.SearchAsync<dynamic>(s => s
    .AllIndices()
    .AllTypes()
    .Query(q => q.Term("_id", "1")));

Hope that helps.

Upvotes: 1

Related Questions