0

I've 3 collections in my database under mongo: shows - venues - dropdowns

shows are mapped like below

"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 like this

"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"
                }
        }
    }

and I've this model in mongo for dropdowns:

{
  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
    }
  }]
}

I'd map dropdowns with parent/child schema into my index, but I can't understand if is possibile with ObjectId because I've tried with this mapping:

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

But I received this error:

MapperParsingException[No type specified for property [show]]

There is anyway to setting up correctly my index?

Evaldas Buinauskas
  • 13,739
  • 11
  • 55
  • 107
Claudio Pomo
  • 2,392
  • 7
  • 42
  • 71

1 Answers1

1

Issue is that you're specifying _parent incorrectly. You have to set it not in properties field, but next to it. Please see documentation and example from it:

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

So following that logic, I've taken your mappings, simplified it a bit and made it work:

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"
          }
        }
      }
    }
  }
}

I've tried this by myself on Elasticsearch 1.7.1 and it worked fine.

However, I'm not sure if you can declare _parent relationship inside nested documents as you did for venues. My mapping query didn't throw an error and accepted it. However, looking on how it got parsed in head plugin - _parent was eliminated and only object part remained as seen in screenshot: Index mappings

If I tried to index it without specifying type - this error is thrown:

"MapperParsingException[mapping [dropdown]]; nested: MapperParsingException[No type specified for property [venues]];

Evaldas Buinauskas
  • 13,739
  • 11
  • 55
  • 107