Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete document types in elasticsearch?

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 index.

How do I get rid of "mytype"?

like image 748
Rolando Avatar asked May 14 '13 14:05

Rolando


People also ask

How do I delete a document in elastic?

You use DELETE to remove a document from an index. You must specify the index name and document ID. You cannot send deletion requests directly to a data stream. To delete a document in a data stream, you must target the backing index containing the document.

Does deleting index delete documents Elasticsearch?

Deleting an index deletes its documents, shards, and metadata. It does not delete related Kibana components, such as data views, visualizations, or dashboards.

How do I delete all index elastic files?

We can delete all the documents from the index using _delete_by_query. when we pass “match_all”:{} then it will match all the documents so _delete_by_query will delete all the documents from the index.

Why type is removed from Elasticsearch?

On top of that, storing different entities that have few or no fields in common in the same index leads to sparse data and interferes with Lucene's ability to compress documents efficiently. For these reasons, we have decided to remove the concept of mapping types from Elasticsearch.


3 Answers

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
like image 200
dadoonet Avatar answered Sep 26 '22 02:09

dadoonet


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

like image 36
yabaiwebyasan Avatar answered Sep 28 '22 02:09

yabaiwebyasan


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.

like image 3
bhargav reddy Avatar answered Sep 28 '22 02:09

bhargav reddy