java - 除非include_type_name设置为true,否则映射定义不能嵌套在类型[_doc]下

标签 java elasticsearch rest-client resthighlevelclient

我的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_nameindex.mapping.single_type看看它是否起作用,并相应地将其添加到您的代码中。

    关于java - 除非include_type_name设置为true,否则映射定义不能嵌套在类型[_doc]下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62803392/

    相关文章:

    elasticsearch - elasticsearch聚合-桶的准确计数

    elasticsearch - ElasticHQ : Unable to Connect to Server! 收到状态码:0

    rest - 如何从Groovy RestClient输出生成的请求和响应?

    spring-mvc - 如何使用 Spring 的 REST 模板传递自定义对象

    java - 如何管理LongClick的时长?

    java - 设置 Nimbus 按钮的按钮 "background"

    c# - 巢-IndexMany不索引我的对象

    java - 是否有类型良好的 Scala(或 Java)库来使用 JSON Web API?

    java - 在 GWT 中——在 JRE 仿真层中使用现有的 Java 类

    选择游戏窗口时 Java 机器人不工作