gpt4 book ai didi

elasticsearch - Elasticsearch :按查询删除不起作用

转载 作者:行者123 更新时间:2023-12-03 00:09:42 24 4
gpt4 key购买 nike

介绍

我正在使用Elastic Search(v5.x),并尝试通过查询删除文档。

我的索引称为“数据”。文档以分层结构存储。使用此模式构建的文档URL:

https://server.ip/data/{userid}/{document-id}



因此,假设用户标识“1”存储了两个文档(“1”,“2”)。因此,他们的直接网址将是:
https://server.ip/data/1/1
https://server.ip/data/1/2

目标

现在,我想做的是从系统中删除用户(用户及其存储的文档)。

对我有用的唯一方法是为每个文档URL发送HTTP DELETE请求。像这样:
DELETE https://server.ip/data/1/1
DELETE https://server.ip/data/1/2

可以了但是,在此解决方案中,我必须多次调用delete。我想一次通话删除所有文档。因此,该解决方案被拒绝。

我的第一次尝试是将HTTP DELETE请求发送到

https://server.ip/data/1



不幸的是,它不起作用(错误代码400)。

我的第二次尝试是使用 _delete_by_query函数。我存储的每个文档都包含 UserId字段,该字段包含UserId。因此,我尝试进行删除查询以删除“数据”索引中所有包含值为1('UserId'== 1)的字段的文档。
POST https://server.ip/data/_delete_by_query
{
"query":{
"match":{
"UserId":"1"
}
}
}

这也行不通。响应是带有以下内容的HTTP错误代码400:
{
"error":{
"root_cause":[
{
"type":"invalid_type_name_exception",
"reason":"Document mapping type name can't start with '_'"
}
],
"type":"invalid_type_name_exception",
"reason":"Document mapping type name can't start with '_'"
},
"status":400
}

您知道如何解决这些问题吗?也许您有替代解决方案?

谢谢!

最佳答案

我假设您已在logstash conf中定义了 document_type ,在output> elasticsearch中定义了以下内容:

output {        
elasticsearch {
index => "1"
document_type => "1type"
hosts => "localhost"
}

stdout {
codec => rubydebug
}
}

因此,您可以简单地删除所有具有相同类型的文档:
curl -XDELETE https://server.ip/data/1/1type

如果您愿意通过查询使用 删除,请尝试执行以下操作:
POST https://server.ip/data/_delete_by_query?UserId=1
{
"query": {
"match_all": {}
}
}

这可能是source的绝对瑰宝。希望能帮助到你!

关于elasticsearch - Elasticsearch :按查询删除不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41998979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com