java - 映射定义不能嵌套在类型 [_doc] 下,除非 include_type_name 设置为 true
问题描述
我的 API 版本是 6.3,我尝试创建索引。失败说“映射定义不能嵌套在类型 [_doc] 下,除非 include_type_name 设置为 true”。这是我的代码:
CreateIndexRequest indexRequest = new CreateIndexRequest("user");
request.source("{\n" +
" \"settings\" : {\n" +
" \"number_of_shards\" : 1,\n" +
" \"number_of_replicas\" : 0\n" +
" },\n" +
" \"mappings\" : {\n" +
" \"_doc\" : {\n" +
" \"properties\" : {\n" +
" \"message\" : { \"type\" : \"text\" }\n" +
" }\n" +
" }\n" +
" },\n" +
" \"aliases\" : {\n" +
" \"twitter_alias\" : {}\n" +
" }\n" +
"}", XContentType.JSON);
CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(indexRequest);
如下删除“_doc”后,失败显示“无法解析映射 [_doc]:没有为字段 [properties] 指定类型”。那我现在该怎么办?
request.source("{\n" +
" \"settings\" : {\n" +
" \"number_of_shards\" : 1,\n" +
" \"number_of_replicas\" : 0\n" +
" },\n" +
" \"mappings\" : {\n" +
"
" \"properties\" : {\n" +
" \"message\" : { \"type\" : \"text\" }\n" +
" }\n" +
"
" },\n" +
" \"aliases\" : {\n" +
" \"twitter_alias\" : {}\n" +
" }\n" +
"}", XContentType.JSON);
解决方案
_doc
是一个临时类型名称,保留它是为了向后兼容并准备删除它,请参阅删除类型以获取更多详细信息。
- 在 6.x 中创建的索引只允许每个索引使用单一类型。该类型可以使用任何名称,但只能有一个。首选类型名称是 _doc,以便索引 API 具有与 7.0 中相同的路径:PUT {index}/_doc/{id} 和 POST {index}/_doc
另请参阅https://www.elastic.co/guide/en/elasticsearch/reference/7.x/removal-of-types.html#_migrating_multi_type_indices_to_single_type本节,其中解释了如何在 6.X 中使用它。
我建议首先尝试使用 REST API 创建一个索引,并查看它的组合include_type_name
是否index.mapping.single_type
有效,然后将其添加到您的代码中。
推荐阅读
- git - 在 Visual Studio 中合并的困惑
- java - java中根据值读取特定对象
- java - Java Collectors.toMap的内存优化
- android-studio - Nox 播放器未在 android studio 中显示
- docker - 有什么方法可以刷新 docker DNS 缓存(内部)?
- node.js - 通过 node-ffi 集成 Node.js 和 C++ DLL 中的奇怪事件行为
- mysql - 获取最高数字并将其自己的记录返回为“该组的代表”
- android - Android:重新计算布局组件的尺寸
- bigcommerce - 我是 BigCommerce 平台的新手。任何人都请告诉我一个页面构建器,我可以用它来设计我在 BigCommerce 上的网页
- python - Python - 将坐标映射到由 numpy.meshgrid 定义的单元格