Elasticsearch DeleteByQuery不工作,收到400个错误请求

本文关键字:400个 错误 请求 收到 DeleteByQuery 工作 Elasticsearch | 更新日期: 2023-09-27 17:57:26

我有下面的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);

谢谢你的帮助。

---------------更新---------------

请求正文

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

响应体

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

感官查询插件:

GET /my-index/type/_search
{
  "query": {
          "match": {
             "versionId": "ea8e517b-c2e3-4dfe-8e49-edc8bda67bad"
          } 
  }
}

查询响应:

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

---------------嵌套查询---------------

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" : [ ]
}

Elasticsearch DeleteByQuery不工作,收到400个错误请求

听起来您可能正在将Elasticsearch 2.x与NEST 2.x结合使用。作为Elasticsearch 2.0的一部分,Delete by query已从Elasticearch核心中移出,并进入需要安装的单独插件中。您可以在Elasticsearch bin目录中使用以下命令安装插件

bin/plugin install delete-by-query

再次启动节点时,"按查询删除"现在应该可以按预期工作了。

如果您需要获得有关请求失败原因的更多详细信息,可以检查响应上的.DebugInformation以获取请求的审计跟踪。