小编Rod*_*Rod的帖子

Elasticsearch java RestHighLevelClient"无法解析响应主体"IllegalArgumentException:必需[index]

使用java创建索引时我处理问题RestHighLevelClientElasticsearch和我CreateIndexResponse对象在结果无效.

我实际上能够创建索引,我可以在稍后查询它,但是当我创建索引时,我得到了这个异常.这是我的代码:

`CreateIndexRequest request = new CreateIndexRequest("myindex"); 
CreateIndexResponse createIndexResponse = client.indices().create(request);`
Run Code Online (Sandbox Code Playgroud)

Elasticsearch返回成功的消息:

`HTTP 200 Success

{
  "acknowledged": true,
  "shards_acknowledged": true
}`
Run Code Online (Sandbox Code Playgroud)

我实际上可以稍后通过GET调用来检索索引,但是当RestHighLevelClient尝试解析响应时,使用以下内部调用:

//Type of the response converter: CheckedFunction<Req, Request, IOException>    requestConverter
responseConverter.apply(response);
Run Code Online (Sandbox Code Playgroud)

发生以下异常:

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]
Run Code Online (Sandbox Code Playgroud)

所以基本上这就是说下面的响应无法解析,但对我来说它看起来很容易解析:

Response{requestLine=PUT /myindex?master_timeout=30s&timeout=30s HTTP/1.1, 
host=http://localhost:9200, response=HTTP/1.1 200 OK}
Run Code Online (Sandbox Code Playgroud)

为什么它告诉我索引丢失了?是不是我错误地使用了Java客户端?这是版本:

<dependencies> …
Run Code Online (Sandbox Code Playgroud)

indexing client parsing elasticsearch

7
推荐指数
1
解决办法
2117
查看次数

标签 统计

client ×1

elasticsearch ×1

indexing ×1

parsing ×1