How to delete document types in elasticsearch?

前端 未结 4 527
没有蜡笔的小新
没有蜡笔的小新 2020-12-31 03:43

I create an index \"myindex\" with a specified document type \"mytype\". I am able to delete the index, but it appears that \"mytype\" still exists without being tied to the

相关标签:
4条回答
  • 2020-12-31 04:13

    In the latest version of elastic search, they no longer support deleting document types. It's mentioned in the documentation

    It is no longer possible to delete the mapping for a type. Instead you should delete the index and recreate it with the new mappings.

    0 讨论(0)
  • 2020-12-31 04:22

    You don't even need to specify the request body. Just

    curl -XPOST http://<host>:9200/<index>/<type>/_delete_by_query
    
    0 讨论(0)
  • 2020-12-31 04:24

    You can use _delete_by_query path to delete type.

    POST index-name/type-name/_delete_by_query
    {
        "query": { 
            "match": {
                "message": "some message"
            }
        }
    }
    

    For further reading see docs

    0 讨论(0)
  • 2020-12-31 04:30

    If you really deleted the index, the mapping in this index should not exist anymore. Do you have any other index in your cluster with a similar type name?

    To answer to the question: How to delete document types in elasticsearch?, use Delete Mapping API:

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

    EDIT: From elasticsearch 2.0, it won't be possible anymore. See Mapping changes. You will have to install the Delete By Query plugin and run a query which will remove your documents but the mapping will still exist. So it will most likely better to reindex your documents in another index without the old type.

    But as @mguillemin and @javanna said, when you delete an index, every mapping attached to this index is deleted as well:

    curl -XDELETE http://localhost:9200/index
    
    0 讨论(0)
提交回复
热议问题