【问题标题】:How can I query concrete Elasticsearch record by its __id?如何通过 __id 查询具体的 Elasticsearch 记录?
【发布时间】:2021-03-22 02:40:37
【问题描述】:
  1. 我有 Elastic 和 Nest。
  2. 我有弹性日志。通过.client.Query(... 查询所有内容我没有任何问题,但是我在使用client.Get 通过其__id 获取一个特定文档时遇到了问题。

我正在使用:

_el_client.Get<SystemLog>(id); // This does not work (_id = QUrLVXgB1uALlflB_-oF)

但是没有返回对象/记录......从Nest客户端查询具体弹性_id的方法是什么?

这是文档的开头(仅供参考)。

 "_index": "webapi-development-2021-03",
  "_type": "_doc",
  "_id": "QUrLVXgB1uALlflB_-oF",
  "_version": 1,
  "_score": null,
  "_source": {
    "@timestamp": "2021-03-21T18:18:55.2173785+01:00",
    "level": "Information",
    "messageTemplate": "{HostingRequestFinishedLog:l}",
    // etc., etc.

感谢您的帮助...

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    好吧,经过多次测试,我找到了解决方案……我必须说官方 DOCS 很烂……这应该是启动示例……最常见的需求……

    1. 使用 Get 时,我需要指定具体的索引,而不仅仅是以 * 结尾的部分

    例子:

     GetResponse<SystemLog> result = _el_client.Get<SystemLog>(request.id, idx => idx.Index("webapi-development-2021-03"));
    
    • 需要为包含 __id + __index 的应用构建 id
    1. 使用搜索(更简单但更慢)
    var response = _el_client.Search<SystemLog>(s => s
        .Query(q => q
           .Ids(i => i
              .Values(request.id)
              )
           )
         );
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    • 2021-12-30
    • 2016-01-11
    相关资源
    最近更新 更多