使用 XContentBuilder 和 RestHighLevelClient 部分更新索引,动态映射严格

问题描述

我创建了一个动态映射严格的文档映射。它有一个嵌套字段,我想使用 RestHighLevelClient for ElasticSearch 对其进行部分更新

private void updateItem(Long itemId,XContentBuilder updateDocument) throws IOException {
UpdateRequest updateRequest = new UpdateRequest(INDEX_NAME,String.valueOf(itemId));
updateRequest.doc(updateDocument,XContentType.JSON).docAsUpsert(false);

try {
  esClient.update(updateRequest,RequestOptions.DEFAULT);
} catch (ElasticsearchException e) {
  log.warn(
      "Elasticsearch error at updating item with id {}\nupdateDocument: {}",productId,Strings.toString(updateDocument));
  throw new IOException("Error at updating item in elasticsearch!",e);
}

}

上面的代码已经有 updateDocument,它是一个嵌套字段(已经是映射的一部分),我正在尝试更新索引 这样做时,我总是收到错误

{"error":{"root_cause":[{"type":"strict_dynamic_mapping_exception","reason":"mapping set to strict,dynamic introduction of [org] within [_doc] is not allowed"}],"type":"strict_dynamic_mapping_exception",dynamic introduction of [org] within [_doc] is not allowed"},"status":400}

我不是在引入新字段,而只是更新作为映射文档一部分的现有嵌套字段。所以我不知道为什么我会收到这个错误

抱歉,如果我没有清楚地表达自己或缺少信息。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)