簡體   English   中英

在 elasticsearch 中可以搜索記錄但不能通過 ID 獲取

[英]In elasticsearch a record can be searched but cannot be fetch by ID

就在這時,發生了一件奇怪的事情。 我曾經在 elasticsearch 集群上運行搜索請求。

curl http://<cluster>/<index>/_search  -H 'Content-Type: application/json' -d' { "query": { "match": { "<field>": "<value>" } } } '

回應是

{ "hits": { "hits": [{ "_id": "<the ID>", ... }], ... }, ... }

然后我試圖查詢這個文檔。

curl http://<cluster>/<index>/_doc/<the ID>

但它回應了

{"_index":"<index>","_type":"_doc","_id":"<the ID>","found":false}

我試圖刪除這條記錄,但也沒有找到。

{"_index":"<index>","_type":"_doc","_id":"<the ID>","_version":1,"result":"not_found","_shards":{ ... }, ... }

我終於使用了 delete by query

什么可能導致這個問題?

Elasticsearch 版本:7.10.2

這通常意味着記錄使用路由值進行索引,這意味着您需要提供該路由值來檢索、更新和/或刪除它。

您可以嘗試不同的路由值,最多為您擁有的主分片數量,即如果您有 5 個主分片,則以下之一必須返回您的文檔

curl http://<cluster>/<index>/_doc/<the ID>?routing=0
curl http://<cluster>/<index>/_doc/<the ID>?routing=1
curl http://<cluster>/<index>/_doc/<the ID>?routing=2
curl http://<cluster>/<index>/_doc/<the ID>?routing=3
curl http://<cluster>/<index>/_doc/<the ID>?routing=4

您可以在_routing字段值的搜索響應中找到用於文檔的路由值。

{ "hits": { "hits": [{ "_id": "<the ID>", "_routing": "<the ROUTING>", ... }], ... }, ... }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM