ElasticSearch数据迁移之reindex

本文档详细介绍了如何使用reindex功能从ElasticSearch 5.4.2版本集群平滑迁移至6.0.0版本集群。内容包括所需的jar包引入,集群连接,mapping结构获取,reindex参数构建,以及ElasticSearch索引获取等步骤。由于使用Ambari安装的ElasticSearch结构和版本差异,不能直接覆盖升级,因此通过编写程序确保数据完整迁移。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需要的jar包,我这里使用maven的pom.xml导入,可以自己下载jar包并导入到项目中

        	<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.24</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-core</artifactId>
			<version>2.10.0</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.2</version>
			<scope>test</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
			<version>4.5.2</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch.client</groupId>
			<artifactId>transport</artifactId>
			<version>5.4.2</version>
		</dependency>
		<dependency>
			<groupId>org.elasticsearch</groupId>
			<artifactId>elasticsearch</artifactId>
			<version>5.4.2</version>
		</dependency>

连接集群ClientConnect.java

package util;

import java.net.InetSocketAddress;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

/**
 * 
 * @createDate 2018年3月8日
 * @class_name ClientConnect 连接ES集群
 * @description : 建立es的client,通过getClient()调用,只能连接es5.4.2
 */
public class ClientConnect {
	private TransportClient client;

	public TransportClient getClient() {
		return client;
	}

	/**
	 * 
	 * @param clusterName            集群名称
	 * @param clusterAddress         集群ip地址
	 * @param port                   端口号
	 */
	@SuppressWarnings({ "unchecked", "resource" })
	public ClientConnect(String clusterName, String clusterAddress, int port) {
		Settings settings = Settings.builder().put("cluster.name", clusterName)
				.build();
		client = new PreBuiltTransportClient(settings)
				.addTransportAddress(new InetSocketTransportAddress(
						new InetSocketAddress(clusterAddress, port)));
		System.out.println("success connect");
	}

}

mapping结构获取与构建Mapping.java

package util;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protoc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值