Startwith query not working if string has hyphen (-)


Hello All,

I am writing a query to fetch items using start with query ... the query returns nothing if the input string has hyphen.

Below is working:

Below is not working:

What should I do to make it work?

Please share suggestions .. thanks in advance.

(David Pilato) #2

That's most likely a question of analyzer.

Have a look at how elasticsearch indexed your document using the _analyze API.
Note that wildcard queries are not analyzed and must exactly match with what you have in the inverted index.

If you don't succeed, please provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.


thanks for quick response and sorry ... your reply is not clear to me .. I created the index using with default settings .. elasticserch-nest was returning correct results .. now I have a requirement to fetch the result through API call and facing these issue (first time working on API queries) .. I just noticed that term query is also not returning result ..


Please help.

(David Pilato) #4

I can't without a script I can run in Kibana Dev console. Could you build one please? Outside the context of .Net.

(Ivan Brusic) #5

If you are using the default settings, then you will be using the standard
analyzer, which uses the standard tokenizer [1]. The standard tokenizer
will split terms on hyphens. In addition, you should not be using term
queries on analyzed fields, unless you know what you are doing. It would be
a good time to understand how analysis works in Elasticsearch/Lucene [2].


(system) closed #6

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