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

时间:2018-02-17 14:27:47

标签: parsing elasticsearch indexing client

我在使用 Elasticsearch 中的java RestHighLevelClient 创建索引时遇到问题,而我的 CreateIndexResponse 对象因此为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>`

提前感谢您的帮助!

0 个答案:

没有答案