首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Monsgoosastic es_indexed不工作

Monsgoosastic es_indexed不工作
EN

Stack Overflow用户
提问于 2015-04-14 10:53:03
回答 1查看 641关注 0票数 0

我有一个模型模式,我想在ElasticSearch中索引它的一部分。根据文档,设置:

代码语言:javascript
复制
es_indexed: true

与所需的模式字段一起,只对与ElasticSearch相关的操作进行索引。我有一个大约20个字段的大模式,其中只需要索引5个字段。

问题是,这些标志被忽略,整个文档被编入索引。

代码语言:javascript
复制
var PersonSchema = new Mongoose.Schema({
    name: {type: String, es_indexed: true},
    address: address: {
        street_address: {type: String},
        locality: {type: String},
        region: {type: String},
        zip: {type: String},
        landmark: {type: String},
        neighbourhood : {type: [String]}
    },
    ...
    tags: {type:[String], index:true, es_indexed: true},
    ...
})

PersonSchema.plugin(mongoosastic);

var Person = Mongoose.model("Merchant", PersonSchema);

在我打电话之后

代码语言:javascript
复制
var stream = Merchant.synchronize()
        , count = 0;

    stream.on('data', function(err, doc){
        count++;
        console.log('indexing: '+ count+ ' done');
    });
    stream.on('close', function(){
        console.log('indexed ' + count + ' documents!');
    });

    stream.on('error', function(err){
        console.log(err);
    });

保存整个文档,包括地址和其他不必要的字段。为什么es_indexed: true标志不能工作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-17 10:27:43

显然,您必须为所有字段提供一个es_indexed属性,以显式地说明是否包括该字段。

代码语言:javascript
复制
var PersonSchema = new Mongoose.Schema({
    name: {type: String, es_indexed: true},
    address: address: {
        es_indexed: false,             //Exclusion needs to be specified as well
        street_address: {type: String},
        locality: {type: String},
        region: {type: String},
        zip: {type: String},
        landmark: {type: String},
        neighbourhood : {type: [String]}
    },
    ...
    tags: {type:[String], index:true, es_indexed: true},
    ...
})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29625511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档