Get documents that have a field with a value prefixing a specified string

Hello Everybody,
I'm looking for a way to get document that have a field which value prefixing a specified string. For a better comprehension, see the following example:

Elasticsearch Document content
CountryCode:33, CountryName:France
CountryCode:34, CountryName:Spain
CountryCode:39, CountryName:France
CountryCode:216, CountryName:Tunisia
CountryCode:212, CountryName:Morocco

A query with "33652729381" will give the line with France as CountryName.

Regards,

It's a question of analysis.

When you search, you want to apply a pattern which transform 33652729381 to:

  • 3
  • 33
  • 336
  • 3365
  • 33652
  • ...

Then you want to compare that with what has been indexed in the CountryCode field and get back that document.

Which means to me:

  • Using a keyword analyzer at index time: "analyzer": "keyword"
  • Using a edge ngram based analyzer at search time: "search_analyzer":"my_ngram_analyzer"

HTH

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