4

实际上,我现在想从某些字段中删除索引,任何人都可以告诉我如何为我的代码给出下面的代码编写映射;任何人都可以告诉我这有什么问题,或者任何人都可以告诉我什么是正确的做法那。

Blog.createMapping(function(err, mapping){
     if(err){
         console.log('error creating mapping (you can safely ignore this)');
         console.log(err);
     }else{
         mapping: {
              properties: {
                  jeb_no: {
                      index: "no"
                  }
              }
         }  
         console.log('mapping created!');
         console.log(mapping);
    }

});

先感谢您。

4

1 回答 1

5

示例:此示例用于保存电影信息

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);
    }
});
于 2016-03-29T05:20:02.490 回答