Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable stemming in Elasticsearch?

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

I currently have a bash script that creates my index. Code is above.

How do I add stemming to it?

like image 341
TIMEX Avatar asked Dec 12 '25 18:12

TIMEX


1 Answers

The most generic way to do it is by replacing default analyzer with snowball analyzer. This will enable stemming for all dynamically-mapped string fields. This is how you can enable english stemmer:

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"
                }
            }
        }
    }
}'
like image 123
imotov Avatar answered Dec 16 '25 14:12

imotov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!