ElasticSearch NEST - 使用 client.Get 在所有索引中搜索文档
ElasticSearch NEST - Using client.Get to get search for a document across all indexes
使用 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 来执行此操作,但这对于检索单个文档而言并不是最佳选择,因此我想尽可能避免。
谢谢
来自 docs for elasticsearch 6.x
Single index APIs such as the Document APIs and the single-index alias
APIs do not support multiple indices.
但您可以在 _id
字段上进行词条查询,以根据 id
检索文档
var response = await client.SearchAsync<dynamic>(s => s
.AllIndices()
.AllTypes()
.Query(q => q.Term("_id", "1")));
希望对您有所帮助。
使用 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 来执行此操作,但这对于检索单个文档而言并不是最佳选择,因此我想尽可能避免。
谢谢
来自 docs for elasticsearch 6.x
Single index APIs such as the Document APIs and the single-index alias APIs do not support multiple indices.
但您可以在 _id
字段上进行词条查询,以根据 id
var response = await client.SearchAsync<dynamic>(s => s
.AllIndices()
.AllTypes()
.Query(q => q.Term("_id", "1")));
希望对您有所帮助。