簡體   English   中英

請求在 Elasticsearch 中通過 id 失敗刪除記錄?

[英]Request to delete record by id failure in Elasticsearch?

我正在學習 Elasticsearch 5,但我還沒有找到刪除已插入其中的數據的方法。

當我查詢列出記錄時,elasticsearch 返回:

curl -X POST \
  http://localhost:9201/usersystem/_search \
  -d '{
    "query": {
        "terms": { "_id": [951] }
    }
}'

返回:

{
   "took":1,
   "timed_out":false,
   "_shards":{
      "total":5,
      "successful":5,
      "skipped":0,
      "failed":0
   },
   "hits":{
      "total":1,
      "max_score":1.0,
      "hits":[
         {
            "_index":"usersystem",
            "_type":"usersystem",
            "_id":"951",
            "_score":1.0,
            "_source":{
               "id":951,
               "name":"User Name",
               "email":"user.name@host.com",
               "phone":"47-1234-9876",
               "documentCode":"9876543-8",
               "documentType":"RR",
               "gender":"MALE",
               "createdOn":"2019-07-04T20:11:47.314Z",
               "updateOn":null,
               "active":false,
               "userId":952
            }
         }
      ]
   }

}

閱讀一些示例,我提出了以下返回錯誤的 DELETE 請求:

要求:

curl -X DELETE \
  http://localhost:9201/usersystem/_query \
  -d '{
    "query": {
        "terms": { "_id": [951] }
    }
}'

錯誤:未No handler found for uri [/usersystem/_query] and method [DELETE]

如何通過 _id 或 id 發出刪除記錄的刪除請求?

做這樣的事情。

curl -X DELETE http://localhost:9201/usersystem/_doc/951

如果您的搜索查詢返回以下響應,

[
  {
    "_index": "usersystem",
    "_type": "usersystem",
    "_id": "951",
    "_score": 1,
    "_source": {
      ....
  }
]

然后從您的搜索查詢的點擊響應中,我們開始知道您的index名稱為usersystemtype usersystem 因此,要按id刪除任何文檔,您可以這樣做-

DELETE /usersystem/usersystem/951

或者

curl -X DELETE "localhost:9201/usersystem/usersystem/951"

查看更多: https : //www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html

我約ElasticSearch文檔中找到_delete_by_query 這是對我有用的申請:

curl -X POST \
  http://localhost:9201/usersystem/_delete_by_query \
  -d '{
    "query": {
        "terms": { "_id": [951] }
    }
}'

暫無
暫無

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

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