简体   繁体   English

Elasticsearch DeleteByQuery无法正常工作,收到400错误请求

[英]Elasticsearch DeleteByQuery not working, getting 400 bad request

I have the following Nest query to delete all the matching documents, quite straight forward but I am getting 400 bad request on it. 我有以下Nest查询来删除所有匹配的文档,很简单,但是我收到了400个错误的请求。

 var client = new ElasticClient();
        var request = new DeleteByQueryRequest<Type>("my-index")
        {
            Query = new QueryContainer(
                    new TermQuery
                    {
                        Field = "versionId",
                        Value = "ea8e517b-c2e3-4dfe-8e49-edc8bda67bad"
                    }
                )
        };
        var response = client.DeleteByQuery(request);
        Assert.IsTrue(response.IsValid);

Thanks for any help. 谢谢你的帮助。

---------------Update--------------- ---------------更新---------------

Request Body 请求正文

{"query":{"term":{"versionId":{"value":"ea8e517b-c2e3-4dfe-8e49-edc8bda67bad"}}}}

Response Body 反应体

{"took":0,"timed_out":false,"_indices":{"_all":{"found":0,"deleted":0,"missing":0,"failed":0}},"failures":[]}

Query in Sense plugin: 在Sense插件中查询:

GET /my-index/type/_search
{
  "query": {

          "match": {
             "versionId": "ea8e517b-c2e3-4dfe-8e49-edc8bda67bad"
          } 

  }
}

Query Response: 查询响应:

{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 116,
      "max_score": 2.1220484,
      "hits": []
...
}}

---------------NEST QUERY-------------- ---------------嵌套查询--------------

DELETE http://localhost:9200/my-index/component/_query?pretty=true
{
  "query": {
    "term": {
      "versionId": {
        "value": "ea8e517b-c2e3-4dfe-8e49-edc8bda67bad"
      }
    }
  }
}

Status: 200
{
  "took" : 0,
  "timed_out" : false,
  "_indices" : {
    "_all" : {
      "found" : 0,
      "deleted" : 0,
      "missing" : 0,
      "failed" : 0
    }
  },
  "failures" : [ ]
}

It sounds like you may be using Elasticsearch 2.x in conjunction with NEST 2.x. 听起来您可能正在将Elasticsearch 2.x与NEST 2.x结合使用。 As part of Elasticsearch 2.0, Delete by query was moved out of Elasticsearch core and into a separate plugin that needs to be installed. 作为Elasticsearch 2.0的一部分,“ 按查询删除”已移出Elasticsearch核心,并移至需要安装的单独插件中。 You can install the plugin using the following command within the Elasticsearch bin directory 您可以在Elasticsearch bin目录中使用以下命令安装插件

bin/plugin install delete-by-query

Starting up the node again, Delete by query should now work as expected. 再次启动节点,按查询删除现在应该可以正常工作。

If you ever need to get more details about why a request has failed, you can inspect the .DebugInformation on the response to get the audit trail for the request. 如果您需要获取有关请求失败原因的更多详细信息,则可以检查响应中的.DebugInformation以获取该请求的审核跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM