How to query like mysql?


(Dennis) #1

hey, there,

I have the following data:
{
"my_key": "hello world"
}

now, I have 2 requirements:

  1. I want to search exactly the string : "hello world", like mysql "="
  2. I want to search "llo wor", like mysql " like '%llo wor%'' "

How can I use ES to do this?

Thanks,
Dennis


(David Pilato) #2

Please format your code using </> icon. It will make your post more readable.

You need to understand how all this works.
By default, when you index hello world, you basically create 2 entries in the inverted index: hello, world.
You can of course use phrase search for your first question.
For the second question, I'd really recommend not using any wildcard query but better index your data as you will query them.

Typically using ngrams, you can index here something like hel, ell, llo, hell, elloand hello. Then searching for llo will match.

Hope this helps


(Dennis) #3

Thank you, David ^-^


(system) #4