0

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

es_indexed: true

与所需的架构字段一起,只会在与 ElasticSearch 相关的操作上索引该键。我有一个大约 20 个字段的大型架构,其中只有 5 个需要被索引。

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

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);

我打电话后

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标志不起作用?

4

1 回答 1

1

显然,您必须为所有字段提供 es_indexed 属性,以明确说明您是否要包含该字段。

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},
    ...
})
于 2015-04-17T10:27:43.790 回答