我myId在索引中有一個帶有 ID 的 ElasticSearch 條目myIndex。此條目具有欄位someExistingField。
現在我想更新這個條目。由于技術原因,更新請求不包含someExistingField資料。
我想確保在此更新的范圍內
- 僅更改更新請求中指定的那些值,并且
- 更新請求中未提及的值不會更改。
目前我正在使用此代碼:
final Map<String, Object> esDocument = ...;
final UpdateRequest request = new UpdateRequest(myIndex, myId);
request.doc(esDocument, XContentType.JSON);
esClient.update(request, RequestOptions.DEFAULT);
我需要如何更改此代碼才能使其不覆寫未在 中指定的現有值request?
uj5u.com熱心網友回復:
這似乎有效:
final UpdateRequest request = new UpdateRequest(myIndex, myId);
...
request.fetchSource(new FetchSourceContext(true,
new String[]{"someExistingField"}, Strings.EMPTY_ARRAY));
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/385576.html
標籤:爪哇 弹性搜索 弹性搜索-java-api
上一篇:將ES升級到5.6.16版本時會拋出錯誤插件[repository-s3]與版本[5.6.16]不兼容;專為[5.2.0]版本設計
