首页 文章

从ElasticSearch中删除数据

提问于
浏览
232

我是ElasticSearch的新手 . 我似乎实际上删除了数据本身 . 我见过的其他东西指的是Delete by Query功能 . 但是,我想知道如何做一个

DELETE FROM [Index]

来自Chrome中的PostMan . 但是,我没有运气 . 似乎无论我做什么,数据都会悬而未决 . 到目前为止,我已经使用PostMan中的DELETE HTTP Verb成功删除了索引并使用了以下URL:

http://localhost:9200/[indexName]

但是,这似乎并没有实际删除数据(也就是文档)本身 .

14 回答

  • 5

    删除索引将删除映射并键入 . 您可以通过以下查询删除所有行

    curl -XDELETE 'localhost:9200/twitter/tweet/_query?pretty' -d'
    {
       "query": { 
          "match_all": 
       }
    }'
    

    但是对于上面的查询,您需要安装按查询删除插件,因为Elasticsearch的2.0.0-beta1从主api中删除了逐个查询

    Install delete-by-query plugin
    
    sudo bin/plugin install delete-by-query
    

    更多

    http://blog.appliedinformaticsinc.com/how-to-delete-elasticsearch-data-records-by-dsl-query/

  • 334

    如果您需要删除所有索引,这可能会派上用场:

    curl -X DELETE 'http://localhost:9200/_all'
    
  • 19

    您可以使用 cURL 删除,也可以使用开源爱好者为Elasticsearch创建的众多工具之一进行直观删除 .

    Using cURL

    curl -XDELETE localhost:9200/index/type/documentID
    

    例如

    curl -XDELETE localhost:9200/shop/product/1
    

    然后,您将收到关于这是否成功的回复 . 您也可以使用索引删除整个索引或类型,您可以通过省略文档ID来删除类型 -

    curl -XDELETE localhost:9200/shop/product
    

    如果您想删除索引 -

    curl -XDELETE localhost:9200/shop
    

    如果您希望删除遵循某个命名约定的多个索引(请注意 * ,一个通配符), -

    curl -XDELETE localhost:9200/.mar*
    

    Visually

    上面提到了各种各样的工具,我不会在这里列出它们,但我会将你链接到一个让你立即开始的工具,位于here . 此工具称为KOPF,要连接到您的主机,请单击左上角的徽标并输入您的群集的URL .

    连接后,您将能够管理整个群集,删除,优化和调整群集 .

  • 283

    您必须发送 DELETE 请求

    http://[your_host]:9200/[your_index_name_here]
    

    您还可以删除单个文档:

    http://[your_host]:9200/[your_index_name_here]/[your_type_here]/[your_doc_id]
    

    我建议你使用elastichammer .

    删除后,您可以使用以下URL查找索引是否仍然存在: http://[your_host]:9200/_stats/

    祝好运!

  • 3

    对于按查询进行批量删除,您可以使用特殊的delete by query API

    $ curl -XDELETE 'http://localhost:9200/twitter/tweet/_query' -d '{
        "query" : {
            "term" : { "user" : "kimchy" }
        }
    }
    

    在历史记录中,API已被删除,然后再次重新引入

    谁有趣它有悠久的历史 .

  • 4

    您可以删除整个索引,doc-type或特定的id数据 . 这些是三种方式:

    • curl -XDELETE localhost:9200 / index_name

    • curl -XDELETE localhost:9200 / index_name / doc-type

    • curl -XDELETE localhost:9200 / index_name / doc-type / documentId

    如果你想删除所有索引,那么去通配符 .

  • 2

    这里有很多好的答案,但也有一些我想补充的内容:

    • 如果您正在 AWS ElasticSearch serviceyou can´t drop/delete indexes 上运行 . Instead of delete indexes, you must reindex them .
  • 2
    #list all index:       curl -XGET http://localhost:9200/_cat/indices?v
    
    #delete index:         curl -XDELETE 'localhost:9200/index_name'
    #delete all indices:   curl -XDELETE 'localhost:9200/_all'
    #delete document   :   curl -XDELETE 'localhost:9200/index_name/type_name/document_id'
    

    安装kibana . Kibana有一个更智能的开发工具,可以帮助您轻松构建查询 .

  • 35

    最简单的方法!

    Endpoint :
    http://localhost:9201/twitter/_delete_by_query
    
    Payload :
    {
      "query": { 
        "match": {
          "message": "some message"
        }
      }
    }
    

    其中 twitter 是弹性搜索中的索引

    参考https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html

  • 3

    我想删除logstash索引,并搜索了很多关于curl等不同工具的信息 . 但最终找到了解决方案 . 登录Kibana . 转到开发工具选项卡,在查询字段中键入 DELETE /logstash-* ,然后单击绿色箭头按钮 . 如果你得到"acknowledged":true表示数据已被清除 .

  • 10

    您还可以使用'elasticsearch head'(Chrome plugin)中的DELETE操作删除索引 . 将其添加到您的Chrome并将其连接到您的主机 . 在那里,您将找到所有索引,如果单击要删除的索引下方的操作按钮,您将在下拉列表中找到DELETE选项 . 单击它并在弹出窗口中输入DELETE . 您的索引将被删除 . 'Elasticsearch head'扩展是查看和管理索引和数据的简便方法 .

  • 2

    documentation(或The Definitive Guide)表示,您还可以使用下一个查询删除所有索引:

    curl -XDELETE 'http://localhost:9200/*'
    

    还有一个重要的注意事项:

    对于某些人来说,使用单个命令删除所有数据的能力是一个非常可怕的前景 . 如果要消除意外批量删除的可能性,可以在elasticsearch.yml中将以下内容设置为true:action.destructive_requires_name:true

  • 1

    使用Curl -L localhost:9200 / _cat / indices - 列出索引

    9200:默认端口[如果使用其他端口则更改端口]

    您可能会发现所有索引都以logstash-yyyy-mm-dd格式开头 . (logstash- *)

    您现在可以列出所有索引并使用

    卷曲-XDELETE localhost:9200 / index_name(这将删除数据和索引) .

  • 2

    您可以在python中删除索引,如下所示

    from elasticsearch import Elasticsearch
    
    es = Elasticsearch([{'host':'localhost', 'port':'9200'}])
    
    es.index(index='grades',doc_type='ist_samester',id=1,body={
        "Name":"Programming Fundamentals",
        "Grade":"A"
    })
    
    es.indices.delete(index='grades')
    

相关问题