How to create mapping for special characters and autocomplete search

Hi,

In my project, I need to search data with special characters like č,ć,ž,đ, ?, !.

What is the best practice for searching special characters in version 8.5?

Also, how to create a mapping for autocomplete search? How to put together special characters and autocomplete features?

Thanks.

Hi @Ismet

Could you give more details about how this autocomplete should work, some documents can help too.
With that I could help you.

Hi @RabBit_BR ,

I use multiple fields for text search (10 fields), those fields have letters, digits, and special characters like -,/,&,č,ć,š,ž,đ.

The string needs to be long min 3 characters and needs to find a result if the string is in the middle of words (search string "or" need to find "word").

Search should include both uppercase and lowercase letters, and blank space.

Is this good solution if i have 10 fileds for full text search and autocomplete search?

PUT my_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "icu_tokenizer",
          "filter": [
            "lowercase",
            "icu_normalizer"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "my_field": {
        "type": "text",
        "analyzer": "my_analyzer",
        "fields": {
          "keyword": {
            "type": "keyword"
          },
          "completion": {
            "type": "completion",
            "analyzer": "my_analyzer",
            "search_analyzer": "my_analyzer",
            "min_input_length": 3
          }
        }
      }
    }
  }
}

Hi @Ismet

I like to use completion suggester as autocomplete solution. Currently my application uses the completion suggester in two fields, in your case it will be 10.

It is worth remembering that you will have to create the inputs for the 10 fields, I don't know if it will be too much work for you, but in fact this solution works.

There are other options like "search-as-you-type" that can also serve this scenario.

I imagined an option (I don't know if it's possible because I haven't tested it), you use copy_to in the 10 fields and copy the values to a single destination field, this destination field can be of the "search-as-you-type" type . So you write a query using only one field that has the values of 10 fields copied.

When searching for full text I recommend having another query for this purpose.

Hi @RabBit_BR, that is a good idea to make one runtime copy_to filed.

search-as-you-type doesn't support special characters like č,ć,š...

In this case, mapping is like this:

PUT my_index
{
  "mappings": {
    "properties": {
      "field_name": {
        "type": "text",
        "analyzer": ["search_as_you_type_analyzer", "special_char_analyzer"]
      }
    }
  },
  "settings": {
    "analysis": {
      "analyzer": {
        "search_as_you_type_analyzer": {
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "nGram"
          ]
        },
       "special_char_analyzer": {
          "tokenizer": "icu_tokenizer",
          "filter": [
            "lowercase",
            "icu_normalizer"
          ]
        }
      },
      "filter": {
        "nGram": {
          "type": "nGram",
          "min_gram": 1,
          "max_gram": 20,
          "token_chars": [
            "letter",
            "digit",
            "punctuation",
            "symbol"
          ]
        }
      }
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.