"Inaccurate" query results when search phrase contains a hyphen


Hi there,

We have a line of products essentially named "product-5", "product-6", "product-7".

We've run into an issue where some users are unhappy that searching with the phrase "product-5" will return not only product-5, but also product-6 and product-7 in the search results.

I've played around with different search phrases such as "product-abc" which will return no results, and "product-532skdfaj" which will return exactly the same results as searching for "product-5".

It seems that when a number follows a hyphen that anything after the hyphen is ignored.

Is there a way to fix this? Or are we going about something the wrong way? This is the code we are executing for the search:

query = client.Search(Language.English).For(searchPhrase)
.InField(v => v.ItemName)
.InField(v => v.ItemLongDesc)

Thanks in advance,

Edited, Sep 14, 2016 6:45

Hi this is probably related to that the - is a special char in ElasticSearch (the component that Find is a wrapper for)

Heres the list of chars that you should look out for.

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \

 '-' unhandled means exclude like + means include in ES

Thees needs escaping like this \-

Dont know if Find handles this but when I wrote my own search, I had to escape these chars otherwise I got exactly the same problem you have.

You can test adding withAndAsDefaultOperator(true) this forces that all the words seperated with (space or special chars) must match.

Hope this helps

Sep 15, 2016 9:44

Hey Daniel,

Thanks for your response. Unfortunately escaping the hyphens didn't work for us.

It seems that escaping the hyphen essentially made find search for "product 5" instead of "product-5".

We are currently using withAndAsDefaultOperator as well.


Sep 20, 2016 1:38
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.