我在Elasticsearch中使用javaRestHighLevelClient创建索引时遇到问题,我的CreateIndexResponse对象在consequence中为null。
我实际上能够创建索引,我可以稍后查询它来确认,但是当我创建索引时,我得到了这个异常。下面是我的代码:
`CreateIndexRequest request = new CreateIndexRequest("myindex");
CreateIndexResponse createIndexResponse = client.indices().create(request);`
Elasticsearch返回成功的消息:
`HTTP 200 Success
{
"acknowledged": true,
"shards_acknowledged": true
}`
实际上,我可以稍后通过GET调用检索索引,但当RestHighLevelClient尝试解析响应时,使用以下内部调用:
//Type of the response converter: CheckedFunction<Req, Request, IOException> requestConverter
responseConverter.apply(response);
发生以下异常:
java.io.IOException: Unable to parse response body for
Response{requestLine=PUT /myindex?master_timeout=30s&timeout=30s HTTP/1.1,
host=http://localhost:9200, response=HTTP/1.1 200 OK}
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:507)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:474)
at org.elasticsearch.client.IndicesClient.create(IndicesClient.java:77)
at hello.client.HelloClient.createSynch(HelloClient.java:84)
at hello.main.Main.main(Main.java:25)
Caused by: java.lang.IllegalArgumentException: Required [index]
所以基本上这就是说,下面的响应不能被解析,但对我来说,它看起来很容易解析:
Response{requestLine=PUT /myindex?master_timeout=30s&timeout=30s HTTP/1.1,
host=http://localhost:9200, response=HTTP/1.1 200 OK}
为什么它告诉我索引丢失了?是我错误地使用了java客户端吗?这是版本:
<dependencies>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.2.1</version>
</dependency>
</dependencies>`
提前感谢您的帮助!
2条答案
按热度按时间3j86kqsm1#
你需要更新你的版本依赖或添加兼容性头(https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/),就我的情况而言,即使是最新版本的Spring-data-elastic search也不支持版本8+的Elastic Search。不得不这样配置我的客户端:
}
vlurs2pr2#
这里需要考虑两件事。下面的示例由连接到Elasticsearch 8.5集群的代码组成。
1.添加自定义页眉
1.正在验证依赖模块
spring-boot-starter-data-elasticsearch
用作依赖项,请使用https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-elasticsearch检查您需要的有效版本Compile Dependencies
部分,以检查你需要使用哪个版本。