在尝试将数据(JSON格式的字符串)上传到ElasticSearch(版本6.3.1)时,restclient将响应发送到9201而不是9200,即使我没有提到9201。Reference
这是我用来设置RestClient的代码-
private static void restWorkPUT() throws IOException {
RestClient restClient = RestClient.builder(
new HttpHost("localhost", 9200, "http")
).build();
jsonDataToUpload = "{\n" + " \"user\" : \"kimchy\",\n" + " \"post_date\" : \"2009-11-15T14:12:12\",\n"
+ " \"message\" : \"trying out Elasticsearch\"\n" + "}";
HttpEntity entity = new NStringEntity(jsonWithIndex,
ContentType.APPLICATION_JSON);
Response indexResponse = restClient.performRequest("POST", "/testabc/abc/1", Collections.<String, String>emptyMap(), entity);
}
现在,当我按下http://localhost:9200/testabc/abc/1时,我看到了响应
{
"error": {
"root_cause": [
{
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_expression",
"resource.id": "testabc",
"index_uuid": "_na_",
"index": "testabc"
}
],
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_expression",
"resource.id": "testabc",
"index_uuid": "_na_",
"index": "testabc"
},
"status": 404
}
当我点击http://localhost:9201/testabc/abc/1时,我会看到响应-
{
"_index": "testabc",
"_type": "abc",
"_id": "1",
"_version": 4,
"found": true,
"_source": {
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "trying out Elasticsearch"
}
}
我希望能够将JSON数据上传到托管在9200的Kibana / ElasticSearch。
任何有关如何解决此问题的建议将不胜感激。