对象映射[位置]无法从嵌套更改为非嵌套

时间:2016-08-19 11:25:57

标签: json elasticsearch

第1步:

PUT http://localhost:9200/hindex

  {
      "mappings" : {
            "hProvider":{
                "properties": {
                    "iPid"  : { 
                        "type": "string"
                    },
                    "pType" : {
                        "type" : "string"
                    },
                    "pInfo" : {
                        "properties":{
                            "businessName": {
                                "type": "string"
                            },
                            "dob": {
                                "type": "string"
                            },
                            "firstName": {
                                "type": "string"
                            },
                            "gender": {
                                "type": "string",
                                "index": "not_analyzed"
                            }
                        }
                    },
                    "locations" : {
                        "type" : "nested",
                        "properties" :  {
                            "addressInfo" : {
                               "properties" : {
                                        "city": {
                                              "type": "string",
                                              "index": "not_analyzed"
                                        },
                                        "county": {
                                              "type": "string",
                                              "index": "not_analyzed"
                                        }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

获取http://localhost:9200/hindex/_mapping

{"hindex":{"mappings":{"hProvider":{"properties":{"iPid":{"type":"string"},"locations":{"type":"nested","properties":{"addressInfo":{"properties":{"city":{"type":"string","index":"not_analyzed"},"county":{"type":"string","index":"not_analyzed"}}}}},"pInfo":{"properties":{"businessName":{"type":"string"},"dob":{"type":"string"},"firstName":{"type":"string"},"gender":{"type":"string","index":"not_analyzed"}}},"pType":{"type":"string"}}}}}}
  1. 插入数据
  2. POST http://localhost:9200/hindex/prof/1/?_create

    {
                   "iPid"  :  "xyz",
                   "pType" : "HealthCareProfessional",
                   "pInfo": {
                      "businessName" : "hdata",
                      "firstName" : "Dawoods",           
                      "dob" : "11/18/1975",
                      "gender" : "male"
                    },
                    "locations" : [
                        {
                            "addressInfo" : {  "city" : "Olney",  "county" : "UnitedStates" } 
                        }, 
                        {
                            "addressInfo" :  {  "city" : "Rivers", "county" : "United States" }
                        }
                    ]
    }
    

    回应:

    {"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[node-1][10.194.153.161:9300][indices:data/write/index[p]]"}],"type":"illegal_argument_exception","reason":"object mapping [locations] can't be changed from nested to non-nested"},"status":400}
    

    尝试了不同的数据集但没有运气,数据上的错误可能是什么?

1 个答案:

答案 0 :(得分:2)

您的第三个命令不正确,它没有在正确的映射类型上运行,它尝试创建一个名为prof的新映射类型,其中包含非嵌套locations字段,该字段与嵌套字符冲突一个在hProvider映射类型的同一索引中。

将其更改为:

POST http://localhost:9200/hindex/hProvider/1/?_create
                                     ^
                                     |
                                change this