i’m new to Elasticsearch and i’ve got a problem regarding querying.
I indexed strings like that:
my-super-string
my-other-string
my-little-string
This strings are slugs.
So, they are no spaces, only alphanumeric characters. Mapping for the related field is only “type=string”.
I’m using a query like this:
{ "query":{ "query_string":{ "query": "*"+<MY_QUERY>+"*", "rewrite": "top_terms_10" } }}
Where “MY_QUERY” is also a slug. Something like “my-super” for example.
When searching for “my” i get results.
When searching for “my-super” i get no results and i’d like to have “my-super-string”.
Can someone help me on this? Thanks!
I would suggest using match_phrase instead of using query string with leading and trailing wildcards. Even standard analyzer should be able to split slug into tokens correctly, so there is not need for wildcards.
Alternatively, you can create your own analyzer that will split slugs into tokens only on “-“