Anuj Mehta
Anuj Mehta

Reputation: 1138

How to match a word without space with ElasticSearch data having space

In my elasticsearch I had data "New York", I want to query and match "NewYork" (please note no space in query string). How can I achieve this? Is there any analyzer that can help here?

Upvotes: 3

Views: 3543

Answers (2)

Mallikarjuna J S
Mallikarjuna J S

Reputation: 130

Here is an example of how to use the Shingle Token Filter to obtain the desired result.

https://arjunjs.wordpress.com/2017/04/02/elasticsearch-how-to-search-for-a-word-without-spaces-if-word-itself-is-combination-of-two-different-words/

Hope this helps.

Upvotes: 0

Ha Hoang
Ha Hoang

Reputation: 1684

I think you can apply to Shingle Token Filter. The shingle filter will create new tokens by concatenating adjacent terms. A part of your query can look like as:

...
"my_shingle":{
   "type":"shingle",
   "max_shingle_size":5,
   "min_shingle_size":2,
   "output_unigrams":"true",
   token_separator: ""
}

Upvotes: 7

Related Questions