首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在nodejs中编写mongoosastic中的映射

如何在nodejs中编写mongoosastic中的映射
EN

Stack Overflow用户
提问于 2015-08-20 23:01:57
回答 1查看 2.7K关注 0票数 4

实际上,我现在想从一些字段中删除索引,有没有人能告诉我,如果我的代码被赋予了bel,我怎么才能写出映射;,有没有人能告诉我这里面有什么问题,或者有没有人能告诉我,这样做的正确方法是什么?

代码语言:javascript
复制
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);
    }

});

提前谢谢你。

EN

回答 1

Stack Overflow用户

发布于 2016-03-29 13:20:02

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

代码语言:javascript
复制
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);
    }
});
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32121783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档