如何在Elasticsearch中启用词干分析?

时间:2013-08-18 22:00:39

标签: lucene elasticsearch

curl -XPUT "localhost:9200/products" -d '{
    "settings": {
        "index": {
            "number_of_replicas" : 0,
            "number_of_shards": 1
        }
    },
    "mappings": {
        "products": {
            "properties": {
                "location" : {
                    "type" : "geo_point"
                }
            }
        }
    }
}'

我目前有一个创建索引的bash脚本。代码在上面。

如何添加词干?

1 个答案:

答案 0 :(得分:6)

最通用的方法是将default分析器替换为snowball分析器。这将启用所有动态映射的字符串字段。这就是你如何启用英语词干分析器:

curl -XPUT "localhost:9200/products" -d '{
    "settings": {
        "index": {
            "number_of_replicas" : 0,
            "number_of_shards": 1,
            "analysis" :{
                "analyzer": {
                    "default": {
                        "type" : "snowball",
                        "language" : "English"
                    }
                }
            }  
        }
    },
    "mappings": {
        "products": {
            "properties": {
                "location" : {
                    "type" : "geo_point"
                }
            }
        }
    }
}'