Search code examples
node.jselasticsearchmongoosemongoosastic

suggester completion issue with mongoosastic 4.x and elasticsearch 2.2


Am tryning to make an autocomplete using mongoosastic I have the following code:

var ItemSchema = new Schema({
    label: {
        type: String,
        required: true,
        es_type: "completion",
        es_analyzer: "simple",
        es_payloads: true
    })

ItemSchema.plugin(mongoosastic);

var ITEM = mongoose.model('Item', ItemSchema);

ITEM.createMapping({}, function(err, mapping) {
    if (err) {
        console.log('error creating mapping (you can safely ignore this)');
        console.log(err);
    } else {
        console.log('mapping created!');
        console.log(mapping);
    }
});

During mapping I got this error message

[illegal_argument_exception] mapper [label] cannot be changed from type [string] to [completion]]

and when I make a search I got the following error

[class_cast_exception] org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType cannot be cast to org.elasticsearch.index.mapper.core.CompletionFieldMapper$CompletionFieldType


Solution

  • I fixed the issue using

    curl -XDELETE localhost:9200/items