我有一个模型架构,其中一部分我想在ElasticSearch中编制索引。根据{{3}},设置:
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
标志不起作用?
答案 0 :(得分:0)
显然,您必须为所有字段提供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},
...
})