Elasticsearch: How do you delete a mapping type wi

2020-07-07 08:39发布

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

4条回答
一纸荒年 Trace。
2楼-- · 2020-07-07 09:01

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.

查看更多
一夜七次
3楼-- · 2020-07-07 09:03

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}
查看更多
男人必须洒脱
4楼-- · 2020-07-07 09:07

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.

查看更多
手持菜刀,她持情操
5楼-- · 2020-07-07 09:08

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

查看更多
登录 后发表回答