ElasticSearch n-gram tokenfilter not finding partial words

前端 未结 2 831
小蘑菇
小蘑菇 2021-02-08 16:58

I have been playing around with ElasticSearch for a new project of mine. I have set the default analyzers to use the ngram tokenfilter. This is my elasticsearch.yml file:

<
相关标签:
2条回答
  • 2021-02-08 17:07

    You should check the get mapping API to see if your mapping has been applied: http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping.html

    Btw it has been said on the mailing list that when an index already contains documents, the mappings you put on the elasticsearch.yml are not applied. You need to clean your index first.

    I've tried ngrams with ES and it works fine for me.

    0 讨论(0)
  • 2021-02-08 17:14

    Not sure about the default_* settings. But applying a mapping that specifies index_analyzer and search_analyzer works:

    curl -XDELETE localhost:9200/twitter
    curl -XPOST localhost:9200/twitter -d '
    {"index": 
      { "number_of_shards": 1,
        "analysis": {
           "filter": {
                      "mynGram" : {"type": "nGram", "min_gram": 2, "max_gram": 10}
                     },
           "analyzer": { "a1" : {
                        "type":"custom",
                        "tokenizer": "standard",
                        "filter": ["lowercase", "mynGram"]
                        }
                      } 
         }
      }
    }
    }'
    
    curl -XPUT localhost:9200/twitter/tweet/_mapping -d '{
        "tweet" : {
            "index_analyzer" : "a1",
            "search_analyzer" : "standard", 
            "date_formats" : ["yyyy-MM-dd", "dd-MM-yyyy"],
            "properties" : {
                "user": {"type":"string", "analyzer":"standard"},
                "message" : {"type" : "string" }
            }
        }}'
    
    curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{
        "user" : "kimchy",
        "post_date" : "2009-11-15T14:12:12",
        "message" : "trying out Elastic Search"
    }'
    
    curl -XGET localhost:9200/twitter/_search?q=ear
    curl -XGET localhost:9200/twitter/_search?q=sea
    
    curl -XGET localhost:9200/twitter/_mapping
    
    0 讨论(0)
提交回复
热议问题