aja*_*ain 6 java spring java-api elasticsearch
我在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"
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我需要删除特定名称的索引和类型.
例如: -从上面的doc,我想删除名为"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"
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
解决方案:
client.admin().indices().delete(new DeleteIndexRequest("test_index").actionGet();
但它删除名为"test_index"的两个索引
我也在感测beta插件中尝试了各种查询,例如:
DELETE/test_index/drama
它给出了错误:找不到uri [/ test_index/drama]和方法[DELETE]的处理程序
DELETE/test_index/drama/_query?q = _id:*&analyze_wildcard = true
它也行不通.
当我在那时触发删除索引请求时,我们不知道索引的id,我只能按名称和类型删除索引.
如何使用java api删除所需的索引?
在使用删除映射 API 的 ES 2.0 之前,这曾经是可能的,但是自 2.0 Delete Mapping
API 以来不再存在。为此,您必须安装“按查询删除”插件。然后,您可以简单地对索引和类型进行匹配所有查询,然后将其全部删除。
查询将如下所示:
DELETE /test_index/drama/_query
{
"query": {
"query": {
"match_all": {}
}
}
}
Run Code Online (Sandbox Code Playgroud)
另请记住,这将删除映射中的文档,而不是映射本身。如果您也想删除映射,则必须在没有映射的情况下重新建立索引。
这也许可以帮助你实现java
归档时间: |
|
查看次数: |
999 次 |
最近记录: |