如何获得来自elasticsearch的客户分析仪来源?

时间:2015-04-30 11:21:09

标签: elasticsearch mapping analyzer

我向elasticsearch发出_mapping请求,并查看是否使用了一个字段自定义分析器。字段的输出如下:

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

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

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

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

1 个答案:

答案 0 :(得分: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