您需要配置索引以使用自定义分析器:
PUT /some_index{ "settings": { ... }, "mappings": { "doc": { "properties": { "test": { "type": "string", "analyzer": "dutch" } } } }}如果您有更多使用此分析器的字段,并且不想为每个分析器指定,则可以针对该索引中的特定类型执行以下操作:
"mappings": { "doc": { "analyzer": "dutch" } }如果希望该索引中的所有类型都使用自定义分析器:
"mappings": { "_default_": { "analyzer": "dutch" } }要以简单的方式测试分析仪:
GET /some_index/_analyze?text=plaatstaal&analyzer=dutch
这将是执行步骤的完整列表:
DELETE /some_indexPUT /some_index{ "settings": { "number_of_replicas": 1, "number_of_shards": 1, "analysis": { "filter": { "dutch_stemmer": { "type": "dictionary_decompounder", "word_list": [ "koud", "plaat", "staal", "fabriek" ] }, "snowball_nl": { "type": "snowball", "language": "dutch" } }, "analyzer": { "dutch": { "tokenizer": "standard", "filter": [ "length", "lowercase", "asciifolding", "dutch_stemmer", "snowball_nl" ] } } } }, "mappings": { "doc": { "properties": { "test": { "type": "string", "analyzer": "dutch" } } } }}POST /some_index/doc/_bulk{"index":{}}{"test": "ijskoud"}{"index":{}}{"test": "plaatstaal"}{"index":{}}{"test": "kristalfabriek"}GET /some_index/doc/_search{ "query": { "match": { "test": "plaat" } }}搜索结果:
{ "took": 1, "timed_out": false, "_shards": { "total": 1, "successful": 1, "failed": 0 }, "hits": { "total": 1, "max_score": 1.987628, "hits": [ { "_index": "some_index", "_type": "doc", "_id": "jlGkoJWoQfiVGiuT_TUCpg", "_score": 1.987628, "_source": { "test": "plaatstaal" } } ] }}


