mongoose-elasticsearch-xp
mongoose-elasticsearch-xp copied to clipboard
Indexing _id field of nested objects
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!
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
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.
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