Nathan Reese
Nathan Reese

Reputation: 2734

Elasticsearch: How do you delete a mapping type without deleting an entire index?

Is it possible to delete a single mapping type from an index without deleting the entire index? https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-mapping.html says that this is not longer possible but I find this hard to believe. Can anyone explain why the functionality was removed? Seems like basic stuff.

I have an index with two mappings. I would like to be able to remove one mapping type (along with all documents of that type) without removing the other mapping type.

Thanks

Upvotes: 14

Views: 38316

Answers (4)

Kalpesh Soni
Kalpesh Soni

Reputation: 7257

I know its a bummer

But that is why we have aliases

While querying we use them

While indexing, you can create an index_2, put new mapping, populate it fully using some batch method

Then change alias from index_1 to index_2

Upvotes: 1

Ajay K. Jain
Ajay K. Jain

Reputation: 101

For latest version(above 2.0) of ES, 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. For more information you can see this in official document here. For the older versions(Below 2.0) of elasticsearch allow to delete a mapping (type) along with its data. The REST endpoints are

[DELETE] /{index}/{type}

[DELETE] /{index}/{type}/_mapping

[DELETE] /{index}/_mapping/{type}

Upvotes: 4

keety
keety

Reputation: 17441

An example of potential problem with deleting types/mapping and the explanation for disabling can be found in elasticsearch issue : 8877. Extract from issue description :

Currently, a user can delete a type entirely, which deletes the type, all documents of that type, and removes the associated fields. Unfortunately, if any documents of that type have already been indexed, then the fields are part of the index. Adding fields with the same name but a different data type will cause conflicts later on.

Currently reindex is the only option however to alleviate the problem of reindexing on client end seems like there maybe a possiblity of support for reindex api in future : see issue:16207 and issue:#15201 for more details.

Upvotes: 5

JVXR
JVXR

Reputation: 1312

To answer your question, I believe it was yanked out for reliability and maybe performance optimizations when the mappings get shipped around the cluster.

The reason why it's hard to change anything in ES index is because the underlying storage is an inverted index, and any data that you have put in has been already indexed with those mapping rules.

Elasticsearch lowers the barrier of entry into search, but has some pretty complicated stuff going under the hood.

Upvotes: 6

Related Questions