【问题标题】:ElasticSearch NEST - Using client.Get to get search for a document across all indexesElasticSearch NEST - 使用 client.Get 跨所有索引搜索文档
【发布时间】:2020-01-06 19:30:50
【问题描述】:

使用 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 执行此操作,但这对于检索单个文档并不是最佳选择,因此我希望尽可能避免。

谢谢

【问题讨论】:

    标签: c# elasticsearch nest


    【解决方案1】:

    来自docs,用于 elasticsearch 6.x

    单索引 API,例如文档 API 和单索引别名 API 不支持多个索引。

    但您可以在_id 字段上进行术语查询以根据 id 检索文档

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

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2020-09-11
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多