D
D
DarkLynx912015-05-26 16:30:49
Node.js
DarkLynx91, 2015-05-26 16:30:49

How to organize an ElasticSearch mongoosastic index?

Good afternoon.
I can't figure out what I'm doing wrong.
There is a scheme

var ResponseSchema = new Schema({
    date_create: {type: Date, default: Date.now},
    author: {type: Schema.Types.ObjectId, ref: 'user', required: true},
    text: {type: String, required: true, es_indexed: true, es_index_analyzer: "index_ru", es_search_analyzer: "search_ru"},
    type: {type: String, default: 'response'},
    type_status: String,
    files: [{type: Schema.Types.ObjectId, ref: 'file'}],
    task: {type: Schema.Types.ObjectId, ref: 'task'}
});

var TicketSchema = new Schema({
    date_create: {type: Date, default: Date.now},
    date_update: Date,
    author: {type: Schema.Types.ObjectId, ref: 'user', required: true},
    project: {type: Schema.Types.ObjectId, ref: 'project', required: true},
    name: {type: String, required: true, es_indexed: true, es_index_analyzer: "index_ru", es_search_analyzer: "search_ru"},
    text: {type: String, required: true, es_indexed: true, es_index_analyzer: "index_ru", es_search_analyzer: "search_ru"},
    status: {type: String, default: 'wait_staff'},
    labor: {type: Boolean, default: false},
    files: [{type: Schema.Types.ObjectId, ref: 'file'}],
    responses: {type: [ResponseSchema]}
});

TicketSchema.plugin(mongoosastic);

var Ticket = mongoose.model('ticket', TicketSchema);
Ticket.createMapping({}, function(err, mapping){
    if (err) {
        console.log(err);
    } else {
        console.log(mapping);
    }
});

As a result, I want to get an index by which the search will be done in the name, text fields of the TicketSchema schema and in the text field of the ResponseSchema schema, which inside the TicketSchema schema is represented by an array of nested ResponseSchema schemas (well, you can see from the code).
If you drop ResponseSchema from the index, then everything works fine, the name and text fields of the TicketSchema schema get into the index, the Russian morphology works - everything is super. But adding another search for ResponseSchema, also taking into account morphology, does not work.
If you write es_type: "nested" for the responses field in TicketSchema, then the ResponseSchema schema objects get into the index, in some scenario (I don’t remember how, I experiment a lot) I even managed to search the ResponseSchema text field and get TicketSchema objects, but without taking into account morphology ..
The question is where and what am I doing wrong...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Shikanov, 2015-05-27
@dizballanze

I would advise you to hang hooks on the models and manually do the indexing separately using the ES client, so you have more control over the process.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question