解决方法:仿照logstash同步原理,对于同步json字符串,首先将其解析,然后添加时间戳和版本字段,或其他字段,打入es。
public void insertEs(String jsonStr){
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
jsonObject.put("@timestamp", new Date());//添加时间戳
jsonObject.put("@version", "1");//添加版本
IndexRequest indexRequest = new IndexRequest(ESIndexName,"doc").source(jsonObject);
try {
highLevelClient.index(indexRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
log.error("入es异常,{}", e);
}
}