简体   繁体   English

使用Java中的elasticSearch 2.3.3按索引名称和类型删除索引

[英]Delete Indexes by index name and type using elasticSearch 2.3.3 in java

I have a project in java where I index the data using elastic search 2.3.3. 我在Java中有一个项目,其中我使用弹性搜索2.3.3索引了数据。 The indexes are of two types. 索引有两种类型。

My index doc looks like: 我的索引文档如下所示:

{
   "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"
            }
         }
      ]
   }
}

I need to delete index of a particular name and type only. 我只需要删除特定名称和类型的索引。

For eg:- From the above doc, I want to delete indexes with Name "test_index" and type "drama" . 例如:-从上面的文档中,我想删除名称为“ test_index”的索引并键入“ drama”

So the result should look like: 因此结果应如下所示:

{
   "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"
            }
         }
      ]
   }
}

Solutions tried: 尝试的解决方案:

client.admin().indices().delete(new DeleteIndexRequest("test_index").actionGet(); client.admin()。indices()。delete(new DeleteIndexRequest(“ test_index”)。actionGet();

But it delete both indexes with name "test_index" 但是它删除两个名称为“ test_index”的索引

I have also tried various queries in sense beta plugin like: 我还尝试了一些有意义的Beta插件查询,例如:

DELETE /test_index/drama 删除/ test_index / drama

It gives the error: No handler found for uri [/test_index/drama] and method [DELETE] 它给出错误: 找不到uri [/ test_index / drama]和方法[DELETE]的处理程序

DELETE /test_index/drama/_query?q=_id:*&analyze_wildcard=true 删除/ test_index / drama / _query?q = _id:*&analyze_wildcard = true

It also doesn't work. 它也不起作用。

When I fire delete index request at that time id of indexes are unknown to us and I have to delete the indexes by name and type only. 当我当时触发删除索引请求时,索引的ID对我们来说是未知的,我只能按名称和类型删除索引。

How can I delete the required indexes using java api? 如何使用Java api删除所需的索引?

This used to be possible till ES 2.0 using the delete mapping API, however since 2.0 Delete Mapping API does not exist any more. 在使用删除映射API的ES 2.0之前,这一直是可能的,但是由于2.0 Delete Mapping API不再存在。 To do this you will have to install the Delete by Query plugin. 为此,您将必须安装“ 按查询删除”插件。 Then you can simply do a match all query on your index and type and then delete all of them. 然后,您可以简单地对索引进行完全匹配查询并键入,然后删除所有查询。

The query will look something like this: 查询将如下所示:

DELETE /test_index/drama/_query
{
  "query": { 
    "query": {
        "match_all": {}
    }
  }
}

Also keep in mind that this will delete the documents in the mapping and not the mapping itself. 还请记住,这将删除映射中的文档,而不是映射本身。 If you want to remove the mapping too you'll have to reindex without the mapping. 如果您也想删除映射,则必须在没有映射的情况下重新索引。

This might be able to help you with the java implementation 可能可以帮助您实现Java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM