【问题标题】:Elasticsearch mapping parser exception?Elasticsearch 映射解析器异常?
【发布时间】:2016-10-12 16:22:03
【问题描述】:

我正在尝试在 Elasticsearch 中创建一个嵌套文档。

结构:

title,name,comments 
  • cmets 是一个嵌套文档 - 在里面 - 评论和 Star_Rating。
  • 内部评论、姓名和地址。

这是下面提到的查询。

PUT /sounduu
    {
    "mappings": {
        "blogpost": {
            "properties": {
                "title": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "comments": {
                    "properties": {
                        "comment": {
                            "properties": {
                                "name": {
                                    "type": "string"
                                },
                                "address": {
                                    "type": "string"
                                }
                            }
                        },
                        "star_rating": {
                            "type": "long"
                        }
                    }
                }
            }
        }
    }
}


PUT /sounduu/blogpost/1
{
    "title": "someh_title",
    "name":"soundy",
    "comments": {
        "comment":"kuu",
        [{
             "name":"juwww",
             "address":"eeeey"
         },
         {
             "name":"jj",
             "address":oo"
        }]
    },
    "star_rating":6
}

错误:

{
   "error": {
      "root_cause": [
         {
            "type": "mapper_parsing_exception",
            "reason": "object mapping for [comments.comment] tried to parse field [comment] as object, but found a concrete value"
         }
      ],
      "type": "mapper_parsing_exception",
      "reason": "object mapping for [comments.comment] tried to parse field [comment] as object, but found a concrete value"
   },
   "status": 400
}

有人可以帮忙吗?

【问题讨论】:

    标签: elasticsearch elasticsearch-query elasticsearch-nested


    【解决方案1】:

    在您的PUT /sounduu/blogpost/1 请求中,您尝试将“comment”属性视为嵌套对象和字符串。

    格式化请求的JSON,可以观察到问题:

    {
        "title": "someh_title",
        "name": "soundy",
        "comments": {
            "comment": "kuu",
            [{
                "name": "juwww",
                "address": "eeeey"
            },
            {
                "name": "jj",
                "address": oo"
            }]
        },
        "star_rating":6
    }
    

    您要么需要更新映射以包含“文本”属性,并相应地移动 "comment": "kuu" 内容,要么从请求中省略它以使用当前映射。

    这里的例子 - 对我来说,这样分组似乎是合乎逻辑的:

    PUT /sounduu
        {
        "mappings": {
            "blogpost": {
                "properties": {
                    "title": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "comments": {
                        "properties": {
                            "text" : {
                                "type": "string"
                            },
                            "name": {
                                "type": "string"
                            },
                            "address": {
                                "type": "string"
                            }
                        }
                    },
                    "star_rating": {
                        "type": "long"
                    }
                }
            }
        }
    }
    

    索引请求将如下所示:

    {
        "title": "someh_title",
        "name": "soundy",
        "comments": [
            {
                "text": "kuu",
                "name": "juwww",
                "address": "eeeey"
            },
            {
                "text": "kuu2",
                "name": "jj",
                "address": oo"
            }
        ],
        "star_rating":6
    }
    

    【讨论】:

    • ryanlutgen - 感谢您的回复。如何使用“文本”属性更新映射并移动评论内容?
    • 我已经编辑了我的答案,并举例说明了在这种情况下我会做什么。
    • 感谢您的回答。同样的情况也适用于我!但我期待的是,例如,我期待在文本中再嵌套一个文档。
    【解决方案2】:

    如果您使用elasticSearch更高版本,则建议将“string”数据类型替换为“text”。 ElasticSearch 社区已丢弃“字符串”。

    修改后的请求应该是:

     `PUT /sounduu
        {
        "mappings": {
            "blogpost": {
                "properties": {
                    "title": {
                        "type": "text"
                    },
                    "name": {
                        "type": "text"
                    },
                    "comments": {
                        "properties": {
                            "text" : {
                                "type": "text"
                            },
                            "name": {
                                "type": "text"
                            },
                            "address": {
                                "type": "text"
                            }
                        }
                    },
                    "star_rating": {
                        "type": "long"
                    }
                    }
                }
            }
        }`
    

    【讨论】:

      猜你喜欢
      • 2021-11-04
      • 2020-12-03
      • 1970-01-01
      • 2014-08-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2023-04-03
      • 2020-03-15
      相关资源
      最近更新 更多