0

私のスキーマは次のようになりますmongoose

var LocationSchema = new Schema({
    id:          ObjectId,
    geo:         { 
        type: {
            type: String,
            required: true,
            enum: ['Point', 'LineString', 'Polygon'],
            default: 'Point'
        },
        coordinates: [{
            type: Number,
            es_lat_lon: true,
            es_type: 'geo_point'
        }]
    }
});

mongoosastic次に、プラグインを追加mongooseしてモデルを開始し、マッピングを作成しますmongoosastic

var esClient = new elasticsearch.Client({
    host: config.es_url,
    requestTimeout: Infinity,
    keepAlive: true
});
LocationSchema.plugin(mongoosastic, { esClient: esClient })

var Location = mongoose.model('Location', LocationSchema);

/**
 * mongoosastic create mappings
 */
Location.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);
    }
});

今、私はこのエラーを受け取ります[Error: MapperParsingException[No handler for type [{default=Point, enum=[Point, LineString, Polygon], required=true, type=string}] declared on field [geo]]]

ログの完全なエラー:

{ 
    [Error: MapperParsingException[No handler for type [{default=Point, enum=[Point, LineString, Polygon], required=true, type=string}] declared on field [geo]]]
    status: '400',
    displayName: 'BadRequest',
    message: 'MapperParsingException[No handler for type [{default=Point, enum=[Point, LineString, Polygon], required=true, type=string}] declared on field [geo]]'
}

私の質問は、私がこれを完全に間違っているのですか、それとも何か小さなものを見逃しているだけですか? 私がこれを行っている方法は、問題がmongooseあるだけであり、その理由を理解していますが、これに最初に遭遇することはできません(問題が発生しているmongoosastic理由は、タイプがあることを見て期待していないためです-少なくとも、それが問題を抱えていると思います)。mongoosastictype

4

1 に答える 1

1

それ以外の

coordinates: [{
        type: Number,
        es_lat_lon: true,
        es_type: 'geo_point'
    }]

試す

coordinates: {
        type: [Number],
        es_type: 'geo_point'
    }

編集

OP このソリューションを投稿しました。かわった:

geo: { 
    type: { 
        type: String, ...... 
    }, 
    coordinates: [
       { type: Number,      ..... }
    ] 
} 

geo: { 
    point_type: { 
        type: String, ...... 
    }, 
    coordinates: [
        { type: Number, ..... }
    ] 
}
于 2016-03-08T15:59:42.963 に答える