Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of data writing failure caused by Elasticsearch type inconsistency

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

In this issue, the editor will bring you about how to solve the problem of data writing failure caused by Elasticsearch type inconsistency. the article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

In versions prior to Elasticsearch 7.x, the following error was reported when ES Client was writing data:

2020-03-13 10 item item: 2634ef87-ec48-4d38-899f-508ba8b69b9c, errorReason: Rejecting mapping update to [journal_test] as the final mapping would have more than 1 type: [2634ef87-ec48, doc] ERROR 9-- [Report ES Thread 0] .g.c.AbstractElasticsearchReportClient:

It means that the type in the data you write is inconsistent with the type you specified when you created the index. For example, I created "_ type": "_ doc" and wrote "_ type": "default". Therefore, there are two ways to either modify the type when the data is written or the type of the current index.

However, there is no such problem in the latest 7.x, because the type feature has been removed.

Considering that changing the type at the time of writing will have to restart the application, which will affect user usage. So the method of modifying the current index is used here.

Provide the simplest solution: back up the current index journal_test to the journal_test_back index and delete the journal_test through the reindex function of Elasticsearch, and let ES automatically generate the index with type as default according to the time of writing data. The backup data is then exported to a file, and the type in the file is modified to default. And then write to the original new journal_test_2 index.

Backup journal_test_2 index data to journal_test_2_bak index: curl-X POST "localhost:9200/_reindex?pretty"-H 'Content-Type: application/json'-d'

{

"source": {

"index": "journal_test"

}

"dest": {

"index": "journal_test_back"

}

}

'

Delete the journal_test index and let ES create its own index when your application writes the data again: curl-X DELETE "http://localhost:9200/journal_test"

Export journal_test_back data to a my_index_mapping.json file

With the help of the tool: https://github.com/taskrabbit/elasticsearch-dump, export the backup data to my local Desktop directory:

Docker run-- rm-ti-v / Desktop:/tmp taskrabbit/elasticsearch-dump\

-- input= http://localhost:9200/journal_test_back\

-- output=/tmp/my_index_mapping.json\

-- type=data

Edit the my_index_mapping.json file to change type to default. Note that in order not to affect the original backup data, I write the modified data to the new file (my_index_mapping_default.json):

Cat my_index_mapping.json | sed s /\ "_ type\":\ "doc\" /\ "_ type\":\ "default\" / > my_index_mapping_default.json

Finally, import the correct data into the correct journal_test index: docker run-- rm-ti-v ~ / Desktop:/tmp taskrabbit/elasticsearch-dump\

-- output= http://localhost:9200/journal_test\ # Note the index name

-- input=/tmp/my_index_mapping_default.json\ # Note the files used here

-- type=data

The above is how to solve the problem of data writing failure caused by Elasticsearch type inconsistency. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 236

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report