如何从 elasticsearch 获取自定义分析器源?

How get custome analyzer source from elasticsearch?

我向 elasticsearch 发出了 _mapping 请求,发现其中一个字段使用了自定义分析器。像这样的字段的输出:

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

那么有没有办法获取 someCustomAnalyzer 的源代码?我试过请求 curl -XGET localhost:9200/_analyze?analyzer=someCustomAnalyzer 得到:

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

如果我为查询字符串添加 text 参数,我得到了用于分析的分析结果,但我需要分析器定义。

你可以用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