ImpalaSQLTargetModel targetModel = generateTestImpalaSQLTargetModel(completedQuery);
                    //构建搜索条件,去索引中查找对应文档的索引,有的话就执行更新操作,没有的话就执行update操作,实现upsert
                    IndexRequest indexRequest = new IndexRequest(INDEX_NAME, TYPE_NAME, "1")
                        .source(JSONObject.toJSON(targetModel).toString(), XContentType.JSON);
                    //当需要update的时候才会设置对应需要更新的字段值
                    setUpsertFieldsValue(completedQuery, targetModel, queryId);
                    //构建update所需的请求参数
                    UpdateRequest updateRequest = new UpdateRequest(INDEX_NAME, TYPE_NAME, "1")
                        .doc(JSONObject.toJSON(targetModel).toString(), XContentType.JSON)
                        .upsert(indexRequest);
                    ActionListener<UpdateResponse> listener = geUpdateResponsetListener();
                    //异步更新
                    CLIENT.updateAsync(updateRequest, listener);
来源:CSDN
作者:JacksonKing
链接:https://blog.csdn.net/JacksonKing/article/details/104611640