mongoose-elasticsearch-xp icon indicating copy to clipboard operation
mongoose-elasticsearch-xp copied to clipboard

Indexing _id field of nested objects

Open botoxparty opened this issue 6 years ago • 3 comments
trafficstars

Hi,

I'm having trouble mapping the _id field of nested objects to elastic search.

For example.

This will map the _id field for assets

const personSchema = new mongoose.Schema({
  name: String,
  age: Number,
  assets: Object
});

Where as this will not...


const assetsSchema = new mongoose.Schema({
  cash: Number,
  property: Number
});

const person = new mongoose.Schema({
  name: String,
  age: Number,
  assets: assetsSchema
});

I'm stumped!

botoxparty avatar Aug 31 '19 19:08 botoxparty

If you don't want mongoose to add an id to the sub schema, you have to explicitly ask for it with:

const assetsSchema = new mongoose.Schema({
  _id: false,
  cash: Number,
  property: Number
});

doc on https://mongoosejs.com/docs/guide.html#id

If you don't get it, I supposed you may have forced it in a way (default config?) btw, this is not a mexp issue, you should ask for it on mongoose tracker

jbdemonte avatar Sep 01 '19 09:09 jbdemonte

I'm not sure why you closed this. I would say it is an issue with mexp as the exact same setup with mongoosastic does infact add the _id field.

The _id field is always written to the database, but it's not synced to elastic search if it's a nested document using mexp. mongoosastic works fine.

botoxparty avatar Sep 01 '19 10:09 botoxparty

My bad, I though you were talking about the _id fields in the mongo db

I do not remember if non explicit ids in sub object were handle automatically, maybe @nodkz may answer

jbdemonte avatar Sep 01 '19 13:09 jbdemonte