【问题标题】:ElasticSearch cannot find newly written documentElasticSearch 找不到新写的文档
【发布时间】:2017-06-06 16:01:10
【问题描述】:

在我的逻辑中,应用程序将文档写入 elasticsearch,它有时会尝试从另一个线程读取它。但是当它尝试读取它时,查询没有返回任何命中。

我假设在 POST 请求(插入)中,当我得到 201 时,这意味着文档已创建。

我的假设是错误的吗?我在这里缺少什么?

感谢您的回复

尼禄

编辑:

保存回复{“_index”:“customers”,“_type”:“customers”,“_id”:“123",“_version”:1,“result”:“created”,“_shards”:{“total”:2,“successful”:2,“failed”:0},“created”:true}

查询请求:

{
  "size": 1,
  "from": 0,
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "id": "123"
          }
        }
      ]
    }
  }
}

查询-响应:

{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

一段时间后,它得到响应,然后点击不是现在。

【问题讨论】:

    标签: elasticsearch indexing


    【解决方案1】:

    查询请求似乎不正确。你应该尝试“_id”而不是“id”:

        {
         "size": 1,
         "from": 0,
         "query": {
                  "bool": {
                           "must": [
                                    {
                                     "match_phrase": {
                                     "_id": "123"
                                        }
                                    }
                                   ]
                         }
                 }
        }
    

    【讨论】:

      【解决方案2】:

      我认为您正在执行 GET 请求,这就是为什么要获得200 状态码。如果是 POST 调用,那么它应该是201 状态码。

      试试这个查询。

      {
        "size": 1,
        "from": 0,
        "query": {
          "bool": {
            "must": [
              {
                "match_phrase": {
                  "_id": "123"
                }
              }
            ]
          }
        }
      }
      

      【讨论】:

      • 感谢您的回复,但我认为情况并非如此。插入不是问题,但我认为当我得到成功响应时,我也应该能够查询并得到它。但它不会发生
      • 您能否在执行 GET 时分享来自 elasticsearch 的一条记录并分享您正在尝试的查询
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多