Baldráni
Baldráni

Reputation: 5640

How do I match a partial result with Elastic Search?

I'm trying to find out how to properly write my query in order to do a LIKE query with ElasticSearch.

Let's say I have a record of firstname and I want to find every one where there is ma in it.

So I've tried multiple things but none are working. Here is a list :

Do you have an idea of how to do that or where am I missing something?

Upvotes: 1

Views: 178

Answers (1)

Ant P
Ant P

Reputation: 25221

You might look into using the N-Gram tokenizer to split your documents' tokens up into their substrings.

This will allow you to search against the index with the "partial" matches you're describing.

Bear in mind that this will affect how your documents are tokenized for search so, if you are using other types of analysis for other parts of your application, you may want to create additional fields for your N-Gram tokenized values (or even create a separate index for them).

As a rule of thumb, always try to optimize your index for the queries you want to perform, rather than trying to solve your search problems at query time.

Upvotes: 1

Related Questions