【总结】Elasticsearch 导出建索引语句

背景

有时候开发中,经常会遇到多个环境间,索引不一致的情况,可能是开发过程中变更原有设计了,但是没有及时更新发布文档,导致上线后,多个环境间不一致。

同样的功能,在开发测试环境没问题,在生产环境出问题。怀疑是索引建的有问题,那么可以通过以下方式,将开发测试环境的索引,重新在生产环境建一遍。

1.备份现有索引

curl --location --request GET 'http://10.10.23.31:9200/roster_20230117test/'
请求得到的结果:
{
    "trade_roster_20230117test": {
        "aliases": {},
        "mappings": {
            "properties": {
                "createBy": {
                    "type": "text"
                },
                "effectFlag": {
                    "type": "integer"
                },
                "entityLabel": {
                    "type": "text"
                },
                "expireTime": {
                    "type": "date",
                    "null_value": "1900-01-01 00:00:01",
                    "format": "yyyy-MM-dd HH:mm:ss"
                },
                "gmtCreate": {
                    "type": "date",
                    "null_value": "1900-01-01 00:00:01",
                    "format": "yyyy-MM-dd HH:mm:ss"
                },
                "gmtModify": {
                    "type": "date",
                    "null_value": "1900-01-01 00:00:01",
                    "format": "yyyy-MM-dd HH:mm:ss"
                },
                "rosterName": {
                    "type": "text"
                },
                "rosterType": {
                    "type": "integer"
                },
                "rosterUuid": {
                    "type": "text"
                },
                "validUnit": {
                    "type": "integer"
                },
                "validValue": {
                    "type": "text"
                },
                "workspaceUuid": {
                    "type": "keyword"
                }
            }
        },
        "settings": {
            "index": {
                "creation_date": "1673926500380",
                "number_of_shards": "1",
                "number_of_replicas": "1",
                "uuid": "9YgfedJzR52SkYhN8TOPmQ",
                "version": {
                    "created": "7090399"
                },
                "provided_name": "trade_roster_20230117test"
            }
        }
    }
}

将结果里的,mapping 和 settings配置,粘贴到以下报文结构的指定内容:
{
“mappings”: {}
“settings”: {}
}

settings部分,仅需要以下两个配置即可。
分片数,按集群节点数1.5~2倍配置
“number_of_shards”: “6”,
副本数,建议配置3
“number_of_replicas”: “3”,

2.恢复索引(不恢复数据)

创建索引,将上述构造好的建索引脚本,粘贴到–data-raw中。注意替换url部分ip、端口、索引名。

curl --location --request PUT 'http://10.10.23.31:9200/roster_20230117test/'' \
--header 'Content-Type: application/json' \
--data-raw '{
    "settings": {
        "index": {
            "number_of_shards": "3",
            "number_of_replicas": "0"
        }
    },
   "mappings": {
            "properties": {
                "createBy": {
                    "type": "text"
                },
                "effectFlag": {
                    "type": "integer"
                },
                "entityLabel": {
                    "type": "text"
                },
                "expireTime": {
                    "type": "date",
                    "null_value": "1900-01-01 00:00:01",
                    "format": "yyyy-MM-dd HH:mm:ss"
                },
                "gmtCreate": {
                    "type": "date",
                    "null_value": "1900-01-01 00:00:01",
                    "format": "yyyy-MM-dd HH:mm:ss"
                },
                "gmtModify": {
                    "type": "date",
                    "null_value": "1900-01-01 00:00:01",
                    "format": "yyyy-MM-dd HH:mm:ss"
                },
                "rosterName": {
                    "type": "text"
                },
                "rosterType": {
                    "type": "integer"
                },
                "rosterUuid": {
                    "type": "text"
                },
                "validUnit": {
                    "type": "integer"
                },
                "validValue": {
                    "type": "text"
                },
                "workspaceUuid": {
                    "type": "keyword"
                }
            }
        }
}'

你可能感兴趣的:(elasticsearch,java)