1.方式一
dump插件
在elasticsearch5.x中
1.1 elasticsearch-dump安装
1) yum install epel-release
2) yum install nodejs
3) yum install npm
4) npm install elasticdump
5) cd node_modules/elasticdump/bin 后便可以执行操作。
1.2 elasticsearch-dump使用
mapping:
./elasticdump --input=http://10.10.10.215:8400/~mdap-china-city_ihl --output=http://10.10.10.138:9200/~mdap-china-city_ihl --type=mapping
data:
2.方式二
代码方式(java 或 python)
java代码:
package com.andong.es.util;
import java.io.File;
import java.io.FileOutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequestBuilder;
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.FilterBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
/**
* ESUtils
*
* @author andong
*
*/
public class ESUtils
{
public final static DateFormat esdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
private final static Logger logger = LoggerFactory.getLogger(ESUtils.class);
/** ES host */
private static String host = "10.10.10.215";
/** ES port */
private static int port = 8500;
/** ES clusterName */
private static String clusterName = "imdap-215";
/** ES client */
private static Client client = new TransportClient(ImmutableSettings.settingsBuilder()
.put("cluster.name", clusterName).build())
.addTransportAddress(new InetSocketTransportAddress(host, port));
public static Client getClient()
{
return client;
}
/**
* 判断是否存在 类型
*
* @param index
* 索引
* @param types
*