【问题标题】:mapping parent/child with _id mongo river elasticsearch使用_id mongo river elasticsearch映射父/子
【发布时间】:2016-01-21 13:49:31
【问题描述】:

我在 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[没有为属性[显示]指定类型]

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

【问题讨论】:

  • 请注意,mongo-river 已被弃用,并从 v2.0 及更高版本中完全删除。

标签: mongodb elasticsearch elasticsearch-plugin elasticsearch-mongo-river


【解决方案1】:

问题是您错误地指定了_parent。您必须不在properties 字段中设置它,而是在它旁边设置它。请参阅documentation 及其示例:

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[映射[下拉]];嵌套: MapperParsingException[没有为属性 [venues] 指定类型];

【讨论】:

    猜你喜欢
    • 2021-03-23
    • 1970-01-01
    • 2019-05-18
    • 2017-12-15
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 2011-12-08
    • 2012-12-18
    相关资源
    最近更新 更多