Squeez
Squeez

Reputation: 959

ElasticSearh searching by part of word if hyphen presents

I have, for example, following strings: 11-22-33, 22-33-44, 33-44-55, 44-55-66 and I'd like to find only 11-22-33. But ES returns me all except last.

Also, later I will need to search by parts *11-22* and it should return me first record.

Upvotes: 0

Views: 58

Answers (2)

Ngen CMS
Ngen CMS

Reputation: 156

I was also having the same problem. Even after doing not_analyzed it was not working. The reason was that the field I added was a new field and I was trying without having modified the mapping. By default, while inserting a not-mapped field, Elasticsearch uses the default mapping.

Upvotes: 1

alpert
alpert

Reputation: 4655

If your fileds are analyzed your strings will be stored as ["11","22","33"], ["22","33","44"], ["33","44","55"], ["44","55","66"]. When you search 11-22-33 it also will be tokenized as ["11","22","33"] and all but the last one have a relevance with that so they will return. If you want store your strings as they are you need to set your fields as not_analyzed

Upvotes: 4

Related Questions