How to set “split_on_numerics” to false in ElasticSearch mapping using ElasticPress? (for proper SKU search in WooCommerce) [closed]

This one was tough, but here is the solution for this!

First, you will need to use SSH to access the server where you have ElasticSearch installed.

After that, you will want to perform these commands:

  • This one will first close your index, only then you can perform changes:

    curl -X POST http://localhost:9200/YOUR-INDEX/_close?pretty

  • This one will put the filter for “word_delimiter”:

    curl -X PUT “localhost:9200/YOUR-INDEX/_settings?pretty” -H ‘Content-Type: application/json’ -d’
    {
    “settings”: {
    “analysis”: {
    “analyzer”: {
    “my_analyzer”: {
    “tokenizer”: “keyword”,
    “filter”: [ “word_delimiter” ]
    }
    }
    }
    }
    }’

  • Then we put the filters we want, like so:

    curl -X PUT “localhost:9200/aYOUR-INDEX/_settings?pretty” -H ‘Content-Type: application/json’ -d’
    {
    “settings”: {
    “analysis”: {
    “analyzer”: {
    “my_analyzer”: {
    “tokenizer”: “keyword”,
    “filter”: [ “my_custom_word_delimiter_filter” ]
    }
    },
    “filter”: {
    “my_custom_word_delimiter_filter”: {
    “type”: “word_delimiter”,
    “type_table”: [ “- => ALPHA” ],
    “split_on_case_change”: false,
    “split_on_numerics”: false,
    “stem_english_possessive”: true
    }
    }
    }
    }
    }’

  • Last but not least, you will want to open your index again, so here we go:

    curl -X POST http://localhost:9200/YOUR-INDEX/_open?pretty

I had to perform all these steps because my index was already created, otherwise it would be basically like we see on the example page.

Hope this helps future visitors. 🙂