我想将 JSON 字符串加载到 Elasticsearch 7.3 版。
以下是我为此使用的代码。
private RestHighLevelClient restHighLevelClient;
String jsonString="//here the complete JSON string";
JSONObject jsonObject = new JSONObject(cojsonStringntent1.toString());
HashMap<String, Object> hashMap = new Gson().fromJson(jsonObject.toString(), HashMap.class);
IndexRequest indexRequest = new IndexRequest("index", "type").source(hashMap);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
异常:线程“main”中的异常 java.lang.NullPointerException 在行
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
如果我通过 POSTMEN 发布相同的 jsonString,那么它将完美地加载到 ELASTICSEARCH。