我有以下的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":[]}
在Sense插件中查询:
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": []
...
}}
--------------- 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" : [ ]
}
答案 0 :(得分:5)
听起来您可能正在将Nlastic 2.x与Elasticsearch 2.x结合使用。作为Elasticsearch 2.0的一部分,需要安装Delete by query was moved out of Elasticsearch core and into a separate plugin。您可以使用Elasticsearch bin目录中的以下命令安装插件
bin/plugin install delete-by-query
再次启动节点,“按查询删除”现在应按预期工作。
如果您需要获取有关请求失败原因的更多详细信息,可以检查响应中的.DebugInformation
以获取请求的审计跟踪。