1

How can I search in elasticsearch field by its exact value but with case insensitive query? For example I have field with value { "Type": "Płatność kartą" }, and my query will search by value "płatność kartą". I need to be able to search by list of string parameters (i.e. "płatność kartą", "płatność gotówką", etc.). I tried elastic TERMS query but it didn't return value when sensitive case difference appears. Field index is set to not_analyzed.

1 Answer 1

3

If you choose not analyzed when indexing, Elastic is not analyzing these terms at index time and that means they are stored verbatim. So when you are querying, you get no results as the query terms don't match the stored fields.

In order to be able to query with lowercase and get the uppercase results, too, you need to use an analyzer on your mapping. Here are the available options from the docs.

If none the available analyzers fit you, you can define your custom one, by specifying the filters you want to be applied. For example, using just the lowercase filter, Elastic will index the RegisteredPaymentType field just lowercased. Then, while querying, the same analyzer will be applied to the query and you will get the expecting results.

Sign up to request clarification or add additional context in comments.

3 Comments

I have changed analyzer to simple and now I hava mapping {"Type":{"type":"string","analyzer":"simple"}}, but when I try to search using terms for text "platność w drodze" I didn't get results. When I search for only one word, for example "platność", I get many result as expected. What I'm doing wrong?
Have you re-indexed the data after changing the mapping? In addition to that, do you consider for example "l" and "ł" the same character? Simple analyzer probably does not handle this difference. Asciifolding filter does.
If use simple analyzer it uses a tokenizer (It will create terms by splitting for empty space so you will get tree terms "platność", "w", "drodze") and when you ask for the term you get the one you need. With simple field I thing will work match_phrase but you need to learn more on analyzsis api if you want to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.