example : この例は映画情報を保存するためのものです
var mongoose = require('mongoose')
Schema = mongoose.Schema,
mongoosastic = require("mongoosastic"),
var MovieSchema = new Schema({
movieName: String,
movieYear: Number,
imageUrl: String,
genre: String,
director: String,
producer: String,
cast: String,
writer: String,
synopsis: String,
rating: Number,
price: Number,
rentPrice: Number,
format: String,
language: String,
offer: Number,
quantity: Number,
offerString: String,
createDate: Date,
updateDate: Date,
});
MovieSchema.plugin(mongoosastic);
Movie = module.exports = mongoose.model('Movie', MovieSchema);
Movie.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": {
"movie": {
"_all": {
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},
"properties": {
"movieName": {
"type": "string",
},
"movieYear": {
"type": "double"
},
"imageUrl": {
"type": "string"
},
"genre": {
"type": "string"
},
"director": {
"type": "string"
},
"producer": {
"type": "string"
},
"cast": {
"type": "String"
},
"writer": {
"type": "string"
},
"synopsis": {
"type": "string"
},
"rating": {
"type": "double"
},
"price": {
"type": "double"
},
"rentPrice": {
"type": "double"
},
"quantity": {
"type": "double"
},
"format": {
"type": "string"
},
"offer": {
"type": "double"
},
"offerString": {
"type": "string"
},
"language": {
"type": "string"
}
}
}
}
}, 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);
}
});