Searching for text combinations

(Paddy Mahadeva) #1


I have a problem i know is definitely not unique, but I am trying to figure what is the smartest way to do this.

I have a name field in my index "name"

the data in it could be

John Doe

john doe


doe JOHN

john mathew doe

any such, I need to run a search on the words john and doe and get all these results. Whats the best way to do this and can I do this with the keyword field or text is the only option?

Currently, I am trying to work with match option. Is there a smarter way to do it?

(Shane Connelly) #2

You've got the right idea!

As a general rule of thumb:

  1. Any time you think of "any/some of the words" as part of a requirement, it means it's text that's going to need to be tokenized into words, which means you're going to want the text type.
  2. Any time you think of "must match the value in the field exactly," then you probably don't need tokenization and therefore keyword is likely a better match.

As some extensions to those that tend to come up next:

  1. If you want to match a phrase within a bigger chunk of text (e.g. match "brown fox" exactly within quick brown fox jumps) you still want text, but you may want to start looking at the phrase queries in Elasticsearch
  2. If you just want to be case insensitive but otherwise match a field value exactly, you can use a keyword with a normalizer

But you're on the right track right now!

(system) #3

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