首页 > 解决方案 > java:Elasticsearch 异常 [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]

问题描述

我正在尝试为索引创建动态模板映射,并且不断收到以下错误:

ElasticsearchStatusException[Elasticsearch 异常 [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: 根映射定义有不受支持的参数:[doc : {properties={price={type=float}, studymodel={type=keyword}, name ={search_analyzer=ik_smart,analyzer=ik_max_word,type=text},描述={search_analyzer=ik_smart,analyzer=ik_max_word,type=text}}}]];嵌套:ElasticsearchException[Elasticsearch 异常 [type=mapper_parsing_exception,reason=Root 映射定义具有不受支持的参数:[doc:{properties={price={type=float},studymodel={type=keyword},name={search_analyzer=ik_smart,分析器=ik_max_word,类型=文本},描述={search_analyzer=ik_smart,分析器=ik_max_word,类型=文本}}}]]];

这是我试图创建映射的代码:

CreateIndexRequest createIndexRequest = new CreateIndexRequest("xc_course");
    createIndexRequest.settings(Settings.builder().put("number_of_shards",1)
            .put("number_of_replicas",0));

    createIndexRequest.mapping("doc"," {\n" +
            " \t\"properties\": {\n" +
            "           \"name\": {\n" +
            "              \"type\": \"text\",\n" +
            "              \"analyzer\":\"ik_max_word\",\n" +
            "              \"search_analyzer\":\"ik_smart\"\n" +
            "           },\n" +
            "           \"description\": {\n" +
            "              \"type\": \"text\",\n" +
            "              \"analyzer\":\"ik_max_word\",\n" +
            "              \"search_analyzer\":\"ik_smart\"\n" +
            "           },\n" +
            "           \"studymodel\": {\n" +
            "              \"type\": \"keyword\"\n" +
            "           },\n" +
            "           \"price\": {\n" +
            "              \"type\": \"float\"\n" +
            "           }\n" +
            "        }\n" +
            "}", XContentType.JSON);
    
    IndicesClient indices = client.indices();  
    CreateIndexResponse createIndexResponse = indices.create(createIndexRequest); 
    boolean acknowledged = createIndexResponse.isAcknowledged();
    System.out.println(acknowledged);

这是映射代码中的错误吗?或者这里一切正常,我应该看看解析映射对象的方式?

标签: javaelasticsearch

解决方案


推荐阅读