0

Elasticsearch初めて使用するテキスト検索を使用して構築しようとしているため、多くの概念を誤解している可能性があります。

インデックス付きフィールドのいずれかに存在する完全な単語を書き込むと、検索は正常に機能しますが、たとえば、私がしようとしているのは、多くの用語を分割するトークナイザーを使用してsamいる製品を取得するときです。 . 注:サーバーで作業するために使用しています。これが製品モデルです。私はそれを呼んでいます:samsungs sa sam samsmongoosasticElasticsearchItem

var ItemSchema = new mongoose.Schema({
    title: {type: String, es_indexed:true, es_analyzer: 'edge_nGram_analyzer'},
    price: Number,
    description: {type: String, es_indexed:true},
    picture: String,
    vendor: {type: String, es_indexed:true},
    vendorId: {type:String, es_indexed:true}
});

と を使用しようとしているモデル コードの残りの部分は次analyzertokenizerとおりです。

    ItemSchema.plugin(mongoosastic, {
        hosts: [
        'localhost:9200'
        ]
    });

    var Item = mongoose.model('Item', ItemSchema);

    Item.createMapping({
"analysis" : {
    "filter": {
        "edgeNGram_filter": {
           "type": "edgeNGram",
           "min_gram": 2,
           "max_gram": 20,
           "side" : "front"
        }
     },
    "analyzer":{
        "edge_nGram_analyzer": {
            "type":"custom",
            "tokenizer":"edge_ngram_tokenizer",
            "filter": [
              "lowercase",
              "asciifolding",
              "edgeNGram_filter"
            ]
        },
        "whitespace_analyzer": {
            "type": "custom",
            "tokenizer": "whitespace",
            "filter": [
              "lowercase",
              "asciifolding"
           ]    
        }
    },
    "tokenizer" : {
        "edge_ngram_tokenizer" : {
          "type" : "edgeNGram",
          "min_gram" : "2",
          "max_gram" : "5",
          "token_chars": [ "letter", "digit" ]
        }   
    }
  }
    },function(err, mapping){
      // do neat things here
      if(err) {
        console.log(err);
      } 
      console.log(mapping);
    });

    module.exports = Item;

これをItem(product) hasでテストtitle : cupcakeしたところ、検索ボックスに入力してcupも何も得られませんでしたが、完全なキーワードを書くとオブジェクトが得られました。

また、ベンダー ID と説明を分析したくありません。これを実行しようとしましvendorId: {type:String, index: 'not_analyzed'}たが、検索用にフィールドのインデックスが作成されなくなりました。

検索エンドポイントのコード:

 app.post('/api/search', function(req, res, next) {
    Item.search({
      query_string: {
        query: req.body.keyword
      }
    },{hydrate:true}, function(err, results) {
      // results here
      res.send(results);
    });
 })
4

1 に答える 1