2015-04-30 63 views
0

我提出了一個_mapping請求elasticsearch,並看到一個字段使用自定義分析器。現場的輸出這樣的:如何從elasticsearch獲取custome分析器源代碼?

"myFieldName": { 
    "type": "string", 
    "analyzer": "someCustomAnalyzer" 
} 

所以是有一種方式來獲得源爲someCustomAnalyzer?我曾嘗試要求curl -XGET localhost:9200/_analyze?analyzer=someCustomAnalyzer 並獲得:

{ 
    "error": "ElasticsearchIllegalArgumentException[text is missing]", 
    "status": 400 
} 

如果我添加text參數的查詢字符串,我得到的分析結果進行分析,但我需要分析的定義。

回答

1

你可以用settings看到它。現在1.5版本的可讀性比以前更高。

所以,如果我創建一個索引與一個不平凡的分析:

PUT /test_index 
{ 
    "settings": { 
     "number_of_shards": 1, 
     "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": { 
     "_all": { 
      "enabled": true, 
      "index_analyzer": "edge_ngram_analyzer", 
      "search_analyzer": "standard" 
     }, 
     "properties": { 
      "first_name": { 
       "type": "string", 
       "include_in_all": true 
      }, 
      "last_name": { 
       "type": "string", 
       "include_in_all": true 
      }, 
      "ssn": { 
       "type": "string", 
       "index": "not_analyzed", 
       "include_in_all": true 
      } 
     } 
     } 
    } 
} 

我可以與索引設置:

GET /test_index/_settings 
... 
{ 
    "test_index": { 
     "settings": { 
     "index": { 
      "creation_date": "1430394627755", 
      "uuid": "78oYlYU9RS6LZ5YFyeaMRQ", 
      "analysis": { 
       "filter": { 
        "edge_ngram_filter": { 
        "min_gram": "2", 
        "type": "edge_ngram", 
        "max_gram": "20" 
        } 
       }, 
       "analyzer": { 
        "edge_ngram_analyzer": { 
        "type": "custom", 
        "filter": [ 
         "lowercase", 
         "edge_ngram_filter" 
        ], 
        "tokenizer": "standard" 
        } 
       } 
      }, 
      "number_of_replicas": "1", 
      "number_of_shards": "1", 
      "version": { 
       "created": "1050099" 
      } 
     } 
     } 
    } 
} 

這裏是我使用的代碼:

http://sense.qbox.io/gist/4a38bdb0cb7d381caa29b9ce2c3c154b63cdc1f8