【发布时间】:2022-01-25 20:19:13
【问题描述】:
我正在尝试将弹性搜索索引从暂存环境克隆到生产环境。找不到办法。我要做的就是用映射而不是数据克隆现有索引。
谁能指出我正确的方向。
【问题讨论】:
标签: elasticsearch-5
我正在尝试将弹性搜索索引从暂存环境克隆到生产环境。找不到办法。我要做的就是用映射而不是数据克隆现有索引。
谁能指出我正确的方向。
【问题讨论】:
标签: elasticsearch-5
没有 1-liner,但如果你有 elasticsearch-python module 并且你只关心映射,这将起作用。
from elasticsearch import Elasticsearch
eshost = <YOUR ELASTICSEARCH HOST>
oldindex = <SOURCE INDEX TO COPY>
newindex = <NEW INDEX>
es = Elasticsearch(eshost)
createReply = es.indices.create(index=newindex)
getReplySource = es.indices.get_mapping(index=oldindex)
sourceMappings = getReplySource[oldindex]['mappings']
for doc_type, mapping in sourceMappings.iteritems():
putReplyTarget = es.indices.put_mapping(doc_type, mapping, newindex)
【讨论】:
在elasticsearch 5.6 和py-elasticsearch 5.5.3 中,以下代码适用于我:
from elasticsearch import Elasticsearch
es = Elasticsearch("your es url")
old_mapping = es.indices.get_mapping('old_index')
es.indices.create(index='new_index')
es.indices.put_mapping(index='new_index', doc_type='type name', body=old_mapping['old_index'])
【讨论】:
同时,还有Elasticsearch Clone index API,你可以使用Python客户端做es.indices.clone(source, target)。
【讨论】: