0

我在 mongo 下的数据库中有 3 个集合:节目 - 场地 - 下拉菜单

节目映射如下

"show": {
    "properties" : {
        "description": {
              "type": "string"
        },
        "image": {
              "type": "string"
         },
        "site": {
              "type": "string"
         },
        "title" : {
                "type" : "multi_field",
                "fields" : {
                    "title" : {"type" : "string", "index" : "analyzed"},
                    "raw_title" : {"type" : "string", "index" : "not_analyzed", "store": "no"}
                }
            }
    }
}

像这样的场地

"venues": {
        "properties" : {
           "name" : {
                    "type" : "multi_field",
                    "fields" : {
                        "name" : {"type" : "string", "index" : "analyzed"},
                        "raw_name" : {"type" : "string", "index" : "not_analyzed", "store": "no"}
                    }
                },
            "city" : {
                    "type" : "multi_field",
                    "fields" : {
                        "city" : {"type" : "string", "index" : "analyzed"},
                        "raw_city" : {"type" : "string", "index" : "not_analyzed", "store": "no"}
                    }
                },
            "region" : {
                    "type" : "multi_field",
                    "fields" : {
                        "region" : {"type" : "string", "index" : "analyzed"},
                        "raw_region" : {"type" : "string", "index" : "not_analyzed", "store": "no"}
                    }
                },
                "state" : {
                    "type": "boolean"
                }
        }
    }

我在 mongo 中有这个模型用于下拉菜单:

{
  created: {
    type: Date,
    default: Date.now
  },
  analytics: {
    type: String,
    default: '',
    trim: true
  },
  state: {
    type: Boolean,
    default: false,
    index: true
  },
  show: {
      type: Schema.ObjectId,
      ref: 'Show'
  },
  venues:[{
    venue:{
      type: Schema.ObjectId,
      ref: 'Venue',
      index: true
    },
    site: {
      type: String,
      trim: true,
      index: true
    }
  }]
}

我会将带有父/子架构的下拉列表映射到我的索引中,但我不明白是否可以使用 ObjectId,因为我已经尝试过使用此映射:

"dropdown": {
            "properties" : {
                "state": {
                     "type": "boolean"
                },
                "analytics": {
                    "type": "string"
                },
                        "_parent":{
                            "type" : "show"
                        },
                "venues" : {
                    "properties" : {
                        "venue" : {
                            "_parent": {
                                "type" : "venues"
                            }
                        }
                    },
                    "site" : {"type" : "string"}
                    }
                }
        }

但我收到了这个错误:

MapperParsingException[没有为属性指定类型 [显示]]

无论如何要正确设置我的索引?

4

1 回答 1

1

问题是您指定_parent不正确。您必须不在properties字段中设置它,而是在它旁边设置它。请参阅其中的文档和示例:

PUT /company
{
  "mappings": {
    "branch": {},
    "employee": {
      "_parent": {
        "type": "branch" 
      }
    }
  }
}

因此,按照该逻辑,我采用了您的映射,对其进行了一些简化并使其工作:

PUT /test
{
  "mappings": {
    "show": {
      "properties": {
        "description": {
          "type": "string"
        },
        "image": {
          "type": "string"
        },
        "site": {
          "type": "string"
        },
        "title": {
          "type": "multi_field",
          "fields": {
            "title": {
              "type": "string",
              "index": "analyzed"
            },
            "raw_title": {
              "type": "string",
              "index": "not_analyzed",
              "store": "no"
            }
          }
        }
      }
    },
    "venues": {
      "properties": {
        "name": {
          "type": "multi_field",
          "fields": {
            "name": {
              "type": "string",
              "index": "analyzed"
            },
            "raw_name": {
              "type": "string",
              "index": "not_analyzed",
              "store": "no"
            }
          }
        },
        "city": {
          "type": "multi_field",
          "fields": {
            "city": {
              "type": "string",
              "index": "analyzed"
            },
            "raw_city": {
              "type": "string",
              "index": "not_analyzed",
              "store": "no"
            }
          }
        },
        "region": {
          "type": "multi_field",
          "fields": {
            "region": {
              "type": "string",
              "index": "analyzed"
            },
            "raw_region": {
              "type": "string",
              "index": "not_analyzed",
              "store": "no"
            }
          }
        },
        "state": {
          "type": "boolean"
        }
      }
    },
    "dropdown": {
      "_parent": {
        "type": "show"
      },
      "properties": {
        "state": {
          "type": "boolean"
        },
        "analytics": {
          "type": "string"
        },
        "venues": {
          "type": "object",
          "_parent": {
            "type": "venues"
          },
          "site": {
            "type": "string"
          }
        }
      }
    }
  }
}

我自己在 Elasticsearch 1.7.1 上尝试过,效果很好。

但是,我不确定您是否可以_parent像在场所中那样声明嵌套文档中的关系。我的映射查询没有抛出错误并接受了它。但是,查看它是如何在 head 插件中解析的 -_parent被消除了,只object保留了一部分,如屏幕截图所示: 索引映射

如果我尝试在不指定类型的情况下对其进行索引 - 将引发此错误:

“MapperParsingException[mapping [dropdown]];嵌套:MapperParsingException[没有为属性 [venues]] 指定类型;

于 2015-10-22T17:03:57.750 回答