high level rest client开发需要注意如下几点:
- 引入的json版本必须与引入es的版本是一致的,如es 6.6.2版本引入的json是2.8.11,则需要引入2.8.11才可以!
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.11</version>
<!--
<version>3.0.0-SNAPSHOT</version>
-->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.11</version>
<!--
<version>3.0.0-SNAPSHOT</version>
-->
</dependency>
- high level版本兼容低版本的rest方式。如下面例子所示,高版本的client不支持通过模板直接创建一个index。
RestClient restClient = client.getLowLevelClient();
Request request = new Request("PUT", "/" + indexName);
Response response = restClient.performRequest(request);
- 创建IndexRequest时,要指定json格式
new IndexRequest(indexName, typeName).source(source, XContentType.JSON)
本文介绍使用Elasticsearch高阶REST客户端(highlevelrestclient)时应注意的事项:保持JSON版本与Elasticsearch版本一致的重要性;高版本客户端对于创建索引的支持限制;及创建IndexRequest时指定JSON格式的要求。
4586

被折叠的 条评论
为什么被折叠?



