【问题标题】:Clone elastic search index with all mappings使用所有映射克隆弹性搜索索引
【发布时间】:2022-01-25 20:19:13
【问题描述】:

我正在尝试将弹性搜索索引从暂存环境克隆到生产环境。找不到办法。我要做的就是用映射而不是数据克隆现有索引。

谁能指出我正确的方向。

【问题讨论】:

    标签: elasticsearch-5


    【解决方案1】:

    没有 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)
    

    【讨论】:

    • 这对我有用,但 iteritems() 需要替换为 items()
    【解决方案2】:

    elasticsearch 5.6py-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']) 
    

    【讨论】:

      【解决方案3】:

      同时,还有Elasticsearch Clone index API,你可以使用Python客户端做es.indices.clone(source, target)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-31
        • 2020-12-17
        • 1970-01-01
        • 2018-05-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多