elasticsearch版本升级迁移总结

最近es环境由5.6.4升级到7.3.2,代码里面有很多需要用高版本的api来重写

个人写了一些迁移的总结,如有错误,望请斧正

 

首先是client,由于es后面将废弃TransportClient,所以代码中都换成RestHighLevelClient

(感觉es 6.0.0是一个版本分界,6.0.0以前是一套,之后是另一套)

 

建立RestHighLevelClient,因为是http方式,所以是9200端口。以前是tcp方式的client,所以用9300端口

RestHighLevelClient restHighLevelClient = new RestHighLevelClient(RestClient.builder(new HttpHost(esClusterAddress, 9200, "http")));

 

用RestHighLevelClient获取集群所有index

GetAliasesRequest request = new GetAliasesRequest();
GetAliasesResponse getAliasesResponse =  restHighLevelClient.indices().getAlias(request,RequestOptions.DEFAULT);
Map> map = getAliasesResponse.getAliases();
Set indices = map.keySet();

删除index中数据

DeleteByQueryRequest request = new DeleteByQueryRequest(indexName);
BulkByScrollResponse response = restHighLevelClient.deleteByQuery(request, RequestOptions.DEFAULT);

删除index

DeleteIndexRequest request = new DeleteIndexRequest("indexName");
AcknowledgedResponse response = restHighLevelClient.indices().delete(request, RequestOptions.DEFAULT);

 

7.0之后看官网说是取消了type

https://www.elastic.co/guide/en/elasticsearch/reference/7.3/mapping.html#field-datatypes

In a cluster composed of both 6.8 and 7.0 nodes, the parameter include_type_name should be specified in index APIs like index creation.

7.0中应该是要指定include_type_name=false

 

在创建index的时候,指定字段include_in_all:false报错

es文档查了半天,发现从6.0开始,去掉了mapping meta data里面的_all。

Deprecated in 6.0.0.
_all may no longer be enabled for indices created in 6.0+, use a custom field and the mapping copy_to parameter

https://www.elastic.co/guide/en/elasticsearch/reference/6.8/mapping-all-field.html

找了一篇不错的介绍https://www.cnblogs.com/wangzhuxing/p/9527151.html#_label1_2

 

 

es head插件以前用的是0.1.2版本,不支持7.3的查询,查询数据一直卡住。于是想安装新版本的es head插件

https://www.cnblogs.com/bu-dong/p/11578027.html

升级到1.0.8之后可以查询了

 

 

未完...

你可能感兴趣的:(elasticsearch版本升级迁移总结)