我的API版本是6.3,我尝试创建索引。失败消息为“除非将include_type_name设置为true,否则映射定义不能嵌套在[_doc]类型下”。这是我的代码:
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
是一个临时类型名称,保留该名称是为了向后兼容并准备删除它,有关此内容的更多详细信息,请引用removal of type。
另请参阅schedule and how to handle this breaking change on your version
在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
看看它是否起作用,并相应地将其添加到您的代码中。
关于java - 除非include_type_name设置为true,否则映射定义不能嵌套在类型[_doc]下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62803392/