【发布时间】:2016-07-27 06:49:31
【问题描述】:
我在 java 中有一个项目,我使用弹性搜索 2.3.3 对数据进行索引。索引有两种类型。
我的索引文档看起来像:
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "movies",
"_id": "uReb0g9KSLKS18sTATdr3A",
"_score": 1,
"_source": {
"genre": "Thriller"
}
},
{
"_index": "test_index",
"_type": "drama",
"_id": "cReb0g9KSKLS18sTATdr3B",
"_score": 1,
"_source": {
"genre": "SuperNatural"
}
},
{
"_index": "index1",
"_type": "drama",
"_id": "cReb0g9KSKLS18sT76ng3B",
"_score": 1,
"_source": {
"genre": "Romance"
}
}
]
}
}
我只需要删除特定名称和类型的索引。
例如:- 从上面的文档中,我想删除名称为 "test_index" 的索引并输入 "drama"。
所以结果应该是这样的:
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "movies",
"_id": "uReb0g9KSLKS18sTATdr3A",
"_score": 1,
"_source": {
"genre": "Thriller"
}
},
{
"_index": "index1",
"_type": "drama",
"_id": "cReb0g9KSKLS18sT76ng3B",
"_score": 1,
"_source": {
"genre": "Romance"
}
}
]
}
}
尝试过的解决方案:
client.admin().indices().delete(new DeleteIndexRequest("test_index").actionGet();
但它会删除名称为“test_index”的两个索引
我还尝试了 sense beta 插件中的各种查询,例如:
删除 /test_index/drama
它给出了错误:No handler found for uri [/test_index/drama] and method [DELETE]
删除 /test_index/drama/_query?q=_id:*&analyze_wildcard=true
它也不起作用。
当我触发删除索引请求时,我们不知道索引的 ID,我必须仅按名称和类型删除索引。
如何使用 java api 删除所需的索引?
【问题讨论】:
-
你安装了delete-by-query plugin吗?最新的查询对我有用,只删除
test_index/drama中的文档
标签: spring elasticsearch java