ElasticSearch Index Analyzer

时间:2015-10-18 16:02:28

标签: elasticsearch spring-data

我使用org.springframework.data.repository.CrudRepository来保存索引。我想使用Ngram分析器进行索引,如何添加自定义索引分析器?

curl -XPUT "http://localhost:9200/blurays " -d'
{
   "settings": {
      "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"
               ]
            },

         }
      }
   },

1 个答案:

答案 0 :(得分:0)

简短回答:您需要在映射字段中使用它。

我为Qbox写了一篇关于Ngrams入门的博文,你可以在这里找到:

An Introduction to Ngrams in Elasticsearch

这是TLDR,希望有助于回答您的直接问题:

PUT /test_index
{
   "settings": {
      "analysis": {
         "filter": {
            "edge_ngram_filter": {
               "type": "edge_ngram",
               "min_gram": 2,
               "max_gram": 20
            }
         },
         "analyzer": {
            "edge_ngram_analyzer": {
               "type": "custom",
               "tokenizer": "standard",
               "filter": [
                  "lowercase",
                  "edge_ngram_filter"
               ]
            }
         }
      }
   },
   "mappings": {
      "doc": {
         "properties": {
            "text_field": {
               "type": "string",
               "index_analyzer": "edge_ngram_analyzer",
               "search_analyzer": "standard"
            }
         }
      }
   }
}