mongoosastic icon indicating copy to clipboard operation
mongoosastic copied to clipboard

Nested elements are not being mapped

Open twboc opened this issue 10 years ago • 2 comments

Mongoosastic version: 4.0.2

I have tried to put a mapping of a nested element and it is not working. Basically I have tried all of the possible combinations obviously including the one presented in the documentation. For some strange reason whenever I put the mapping all of the mongo document properties are being mapped properly except the ones with es_type : "nested". This is how I created the document with nested elements.

var LabelsSchema = new Schema({
    text: {
        type: String,
        default: null
        , es_index: 'not_analyzed'
    },
    lang: {
        type: String,
        enum: _.pluck(config.languages, 'code'),
        default: 'en'
    }
});

var DomainSchema = new Schema({

        labels: {

            type: [Labels.LabelsSchema]
            , es_indexed: true
            , es_type: 'nested'
            , es_include_in_parent: true

        }

});


DomainSchema.plugin(mongoosastic, {
    hosts: config.elastic.hosts
});

var Domain = mongoose.model('Domain', DomainSchema);

Domain.esTruncate();
Domain.createMapping(config.mapping, function (err, mapping) {

    if (err) {
        console.log(err);
    }
});

var stream = Domain.synchronize();
stream.on('error', function (err) { });


From what I have read this is somehow broken since quite a while. Or maybe I am declaring the nested type in a wrong way.

Could anyone give me advice or this is a bug ????

twboc avatar Mar 14 '16 12:03 twboc

Hi, in order to map nested elements you just to write labels: { type: [LabelsSchema] }

Other options are not needed

ksavidetove avatar Dec 12 '16 19:12 ksavidetove

this is not working in the latest version

aryeharmon avatar Mar 20 '17 07:03 aryeharmon