如何整合Mongoosastic?

时间:2019-02-06 08:42:01

标签: node.js mongodb elasticsearch mongoose mongoosastic

ELASTICSEARCH的全新功能

我有一个mongoose schema定义

const newSchema = new mongoose.Schema({
    name: String,
    age: Number,
    interests: [Objects],
});

newSchema.plugin(mongoosastic);

New = module.exports = mongoose.model('New', newSchema);

New.createMapping({
    "settings": {
        "number_of_shards": 1,
        "number_of_replicas": 0,
        "analysis": {
            "filter": {
                "nGram_filter": {
                    "type": "nGram",
                    "min_gram": 2,
                    "max_gram": 20,
                    "token_chars": [
                        "letter",
                        "digit",
                        "punctuation",
                        "symbol"
                    ]
                }
            },
            "analyzer": {
                "nGram_analyzer": {
                    "type": "custom",
                    "tokenizer": "whitespace",
                    "filter": [
                        "lowercase",
                        "asciifolding",
                        "nGram_filter"
                    ]
                },
                "whitespace_analyzer": {
                    "type": "custom",
                    "tokenizer": "whitespace",
                    "filter": [
                        "lowercase",
                        "asciifolding"
                    ]
                }
            }
        }
    },
    "mappings": {
        "new": {
            "_all": {
                "analyzer": "nGram_analyzer",
                "search_analyzer": "whitespace_analyzer"
            },
            "properties": {
                "name": {
                    "type": "string",
                },
                "age": {
                    "type": "string",
                },
                "interests": {
                    "type": "string",
                },
            }
        }
    }
}, function(err, mapping) {
    if (err) {
        console.log('error');
        console.log(err);
    } else {
        console.log('mapping created!');
        console.log(mapping);
    }
});

当我运行上面的项目时,出现错误:

  

消息:'[mapper_parsing_exception]没有用于类型[string]的处理程序   在字段[age]'

上声明

我在做什么错了?我对弹性搜索完全陌生。

我什至不了解Elasticsearch,上面的createMapping函数是从互联网复制的。

0 个答案:

没有答案