使用NEST v6.4.2
我需要使用client.Get API来获取在所有索引而不是一个索引中搜索的文档。
我的代码如下:
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));
以前有人这样做吗?文档似乎表明您可以使用client.Search API来执行此操作,但这并不是检索单个文档的最佳选择,因此我希望尽可能避免。
谢谢
从elasticsearch 6.x的docs起>
单索引API,例如文档API和单索引别名API不支持多个索引。
但是您可以在
_id
字段上进行术语查询以根据ID检索文档
var response = await client.SearchAsync<dynamic>(s => s .AllIndices() .AllTypes() .Query(q => q.Term("_id", "1")));
希望有所帮助。