父,子,孙子映射elasticsearch json解析错误

时间:2017-07-11 11:52:08

标签: json elasticsearch mapping parent-child parse-error

我已经存在索引名称test-migrate。我想通过自定义映射将数据添加到其中,以实现父子孙关系。我收到指定索引的解析错误。你能指出我的错误。

curl -XPUT 'http://url:9200/test-migrate'

{"acknowledged":true,"shards_acknowledged":true}

以下是我的映射的样子:

curl -XPUT 'url:9200/test-migrate/type/_mapping' -d  '
{
  "type" : {
   "dynamic": "strict",
    "properties" : {
      "@timestamp" : {
        "type" : "date"
      },
      "@version" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },
      "sub" : {
      "properties" : {
            "mnumber" : {
        "type" : "long"
      },
      "pnumber" : {
        "type" : "long"
      },
      "s_id" : {
        "type" : "long"
      },
      "s_name" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      }
      }
      },
      "comp": {
        "_parent": {
       "type" : "sub"
       },
      "properties" : {
      "comp_id" : {
        "type" : "long"
      },
      "comp_name" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      }
      }
      },
      "we" : {
       "_parent" : {
      "type"  :  "comp"
      },
      "_routing"  : {
      "type" :  "sub"
      },
      "properties" : {
      "we_1" : {
        "type" : "float"
      },
      "we_2" : {
        "type" : "float"
       }
      }
     }
    }
  }
}
'

但是当我执行它时,我收到一条错误消息:

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Mapping definition for [comp] has unsupported parameters:  [_parent : {type=sub}]"}],"type":"mapper_parsing_exception","reason":"Mapping definition for [comp] has unsupported parameters:  [_parent : {type=sub}]"},"status":400}

1 个答案:

答案 0 :(得分:0)

这应该有效。结构与映射结构存在问题,其他类型的映射必须定义为单独的映射对象。

    PUT parent_index
    {
    "mappings": {
        "type": {
            "dynamic": "strict",
            "properties": {
                "@timestamp": {
                    "type": "date"
                },
                "@version": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        },
        "sub": {
                    "properties": {
                        "mnumber": {
                            "type": "long"
                        },
                        "pnumber": {
                            "type": "long"
                        },
                        "s_id": {
                            "type": "long"
                        },
                        "s_name": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        }
                    }
                },
        "we": {
            "_parent": {
                "type": "comp"
            },
            "_routing": {
                "type": "sub"
            },
            "properties": {
                "we_1": {
                    "type": "float"
                },
                "we_2": {
                    "type": "float"
                }
            }
        },
        "comp": {
            "_parent": {
                "type": "sub"
            },
            "properties": {
                "comp_id": {
                    "type": "long"
                },
                "comp_name": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }
}

注意: 您正在寻找的其他方式。

首先,创建索引

PUT test-migrate

第二次,现在添加类型

的映射
POST test-migrate/_mapping/type
   {
    "type": {
        "dynamic": "strict",
        "properties": {
            "@timestamp": {
                "type": "date"
            },
            "@version": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
        }
    },
    "sub": {
        "properties": {
            "mnumber": {
                "type": "long"
            },
            "pnumber": {
                "type": "long"
            },
            "s_id": {
                "type": "long"
            },
            "s_name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
        }
    },
    "we": {
        "_parent": {
            "type": "comp"
        },
        "_routing": {
            "type": "sub"
        },
        "properties": {
            "we_1": {
                "type": "float"
            },
            "we_2": {
                "type": "float"
            }
        }
    },
    "comp": {
        "_parent": {
            "type": "sub"
        },
        "properties": {
            "comp_id": {
                "type": "long"
            },
            "comp_name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
        }
    }
}