导⼊导出elasticarch 索引数据
1.⽅式⼀
dump 插件
在elasticarch5.x中
1.1 elasticarch-dump 安装
1.2 elasticarch-dump 使⽤
mapping: data:
2.⽅式⼆
代码⽅式(java 或 python)
java代码:
package com.andong.es.util;
import java.io.File;
import java.io.FileOutputStream;
DateFormat;
SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import s.lang.StringUtils;
import org.apache.poi.hssf.urmodel.HSSFCell;
import org.apache.poi.hssf.urmodel.HSSFCellStyle;
import org.apache.poi.hssf.urmodel.HSSFFont;
import org.apache.poi.hssf.urmodel.HSSFRow;
import org.apache.poi.hssf.urmodel.HSSFSheet;
import org.apache.poi.hssf.urmodel.HSSFWorkbook;
import org.elasticarch.action.ists.indices.IndicesExistsRequestBuilder;
import org.elasticarch.action.ists.indices.IndicesExistsRespon;
import org.elasticarch.action.pes.TypesExistsRequestBuilder;
import org.elasticarch.action.pes.TypesExistsRespon;
import org.elasticarch.action.bulk.BulkRequestBuilder;
import org.elasticarch.action.bulk.BulkRespon;
import org.elasticarch.action.arch.SearchPhaExecutionException;
import org.elasticarch.action.arch.SearchRequestBuilder;import org.elasticarch.action.arch.SearchRespon;
1) yum install epel-relea
2) yum install nodejs
3) yum install npm
4) npm install elasticdump
5) cd node_modules/elasticdump/bin 后便可以执⾏操作。
import org.elasticarch.action.arch.SearchRespon;
import org.elasticarch.action.arch.SearchType;
import org.elasticarch.client.Client;
import org.elasticarch.client.IndicesAdminClient;
import org.ansport.TransportClient;
import ings.ImmutableSettings;
import ansport.InetSocketTransportAddress;
import org.elasticarch.index.query.FilterBuilder;
import org.elasticarch.index.query.QueryBuilder;
import org.elasticarch.arch.SearchHit;
import org.elasticarch.arch.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 = Logger(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 ingsBuilder()
.put("cluster.name", clusterName).build())
.addTransportAddress(new InetSocketTransportAddress(host, port));
public static Client getClient()
{
return client;
}
/**
* 判断是否存在类型
*
* @param index
* 索引
* @param types
* 类型
* @return
*/
public static boolean isTypeExists(String index, types)
{
IndicesAdminClient indexClient = client.admin().indices();
TypesExistsRequestBuilder typeExist = null;
if (index == null || index.equals(""))
{
typeExist = indexClient.prepareTypesExists();
}
el
{
typeExist = indexClient.prepareTypesExists(index);
typeExist = indexClient.prepareTypesExists(index);
}
TypesExistsRequestBuilder typeExists = typeExist.tTypes(types);
TypesExistsRespon respon = ();
return respon.isExists();
}
/**
* 判断是否存在索引
*
* @param indice
* 索引
* @return
*/
public static boolean indice)
{
IndicesExistsRequestBuilder indexExists = client.admin().indices().prepareExists(indice);
IndicesExistsRespon respon = ();
return respon.isExists();
}
public static void inrtOne(String index,String type,Object data){
List<Object> datas = new ArrayList<Object>();
datas.add(data);
ESUtils.inrt(index, type, datas);
}
/**
* 写ES库
*
* @param index
* 索引
* @param type
* 类型
* @param datas
*/
public static void inrt(String index, String type, List<Object> datas)
{
怎么拉韧带
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (Object data : datas)
{
String dataStr = JSONStringWithDateFormat(data, "yyyy-MM-dd'T'HH:mm:ss.SSS");
东北五校bulkRequest.add(client.prepareIndex(index, type).tSource(dataStr));
}
BulkRespon bulkRespon = ute().actionGet();
}
public static Pageable arch(String[] indexs,String type, FilterBuilder filterBuilders, QueryBuilder queryBuilders, LinkedHashMap<String, SortOrder> orders, int from, int size)
{
Pageable page = new Pageable<Object>();
try
{
if (from < 0)
{
from = 0;
}
if (size < 0)
{
size = 10;
}
SearchRequestBuilder archRequestBuilder = client.prepareSearch();
if (!StringUtils.isEmpty(type))
{
if(type.split(",").length<=1){
archRequestBuilder.tTypes(type);
}el{
archRequestBuilder.tTypes(type.split(","));
}
}
if (orders != null && !orders.isEmpty())
{
for (String key : orders.keySet())
{
archRequestBuilder.addSort(key, (key));
}
}
SearchRespon respon = archRequestBuilder.tSearchType(SearchType.DFS_QUERY_THEN_FETCH) .tQuery((QueryBuilder) queryBuilders) // Query
.tPostFilter((FilterBuilder) filterBuilders) // Filter
.tFrom(from).tSize(size).tExplain(fal).execute().actionGet();
SearchHit[] ss = Hits().getHits();
List<Map<String, Object>> datas = new ArrayList<Map<String, Object>>();
Map<String, Object> data = null;
for (SearchHit s : ss)
{
data = s.getSource();
datas.add(data);
}
page.Hits().getTotalHits());
page.tContent(datas);
}
爱的困惑catch (SearchPhaExecutionException e)
{
page.tTotal(0L);
}
// }
return page;
}
/* *//**
* 解析返回的数据
*
* @param content
* @return
* @throws Exception
*//*
public static EsResult parEs(String content) throws Exception
{
EsResult esResult = new EsResult();
Gson gson = new Gson();
Type type = new TypeToken<Map<String, Object>>()
{
}.getType();
获取查询时长
Map<String, Object> map = gson.fromJson(content, type);
// logger.debug("ES执⾏查询结果数据"+String());
/
/ logger.debug("ES执⾏查询结果数据"+String());
long took = ((Double) ("took")).longValue();
esResult.tTook(took);
logger.debug("ES执⾏查询时长" + Took());
获取查询总数
Map<String, Object> _hits = (Map) ("hits");
esResult.tTotal(((Double) _("total")).intValue());
校园的早晨如果总数为0
logger.debug("ES执⾏查询总数" + Total());
if (Total() == 0)
{
return esResult;
}
获取查询的结果集并解析成JavaBean
esResult.tParaBefore((List) _("hits"));
返回统计结果集Map 这⾥不处理具体类处理
esResult.tFacets(parLogFaces((Map) ("aggregations")));
return esResult;
}
探索太空
*/
public static void main(String[] args) throws Exception
{
ESUtils esUtils = new ESUtils();
boolean typeExists = esUtils.isTypeExists("~mdap-china-city_ihl", "province");
if(typeExists) {
String[] indexs= {"~mdap-china-city_ihl"};
FilterBuilder filterBuilders = null;
QueryBuilder queryBuilders = null;
LinkedHashMap<String, SortOrder> orders = null;
Pageable arch = esUtils.arch(indexs, "province", filterBuilders, queryBuilders, orders, 0, 10000); List<Map<String, Object>> content = Content();
//esUtils.parEs(content);
// 创建execl ⽂件
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = ateSheet();
// 设定默认宽度
sheet.tDefaultColumnWidth(18);
// 数字double样式
HSSFCellStyle contentCellStyle = ateCellStyle();
HSSFFont font = ateFont();
font.tFontName("宋体");
font.tFontHeightInPoints((short) 11);
contentCellStyle.tFont(font);
// 标题样式
HSSFCellStyle headerStyle = (HSSFCellStyle) ateCellStyle();// 创建标题样式
headerStyle.tVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); // 设置垂直居中
headerStyle.tAlignment(HSSFCellStyle.ALIGN_CENTER); // 设置⽔平居中
家族祠堂对联HSSFFont headerFont = (HSSFFont) ateFont(); // 创建字体样式
headerFont.tBoldweight(HSSFFont.BOLDWEIGHT_BOLD); // 字体加粗
headerFont.tFontName("Times New Roman"); // 设置字体类型
headerFont.tFontHeightInPoints((short) 12); // 设置字体⼤⼩
headerStyle.tFont(headerFont); // 为标题样式设置字体样式
HSSFRow row = null;
HSSFCell cell = null;
StringBuffer idBuffer = new StringBuffer("");
LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
服从的近义词row = ateRow(0);
cell = ateCell(0);
cell.tCellValue("name");
cell = ateCell(1);
cell.tCellValue("IN_TIME");
cell = ateCell(2);