# Hyphens in query\_string

**URL:** <https://discuss.elastic.co/t/hyphens-in-query-string/6006>\
**Category:** Elasticsearch\
**Created:** [November 29, 2011, 11:00am UTC](https://discuss.elastic.co/t/hyphens-in-query-string/6006 "2011-11-29T11:00:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![avasilenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avasilenko/32/2901_2.png) [@avasilenko](https://discuss.elastic.co/u/avasilenko)\
**Post date:** [November 29, 2011, 11:00am UTC](https://discuss.elastic.co/t/hyphens-in-query-string/6006/1 "2011-11-29T11:00:26Z")

</div>

Hello,

Is it possible to consider hyphen (separate by spaces) in query\_string as a  
hyphen, rather than lucene "minus" (like explained in lucene  
[http://lucene.apache.org/java/3\_4\_0/queryparsersyntax.html#-](http://lucene.apache.org/java/3_4_0/queryparsersyntax.html#-))? E.g.  
consider it as "minus", when it's followed by the word, not space.

Reproduce:  
Consider following mapping -  
[https://gist.github.com/1404391#file\_mapping.json](https://gist.github.com/1404391#file_mapping.json) and content  
[https://gist.github.com/1404391#file\_content.json](https://gist.github.com/1404391#file_content.json) . Address contains  
hyphen, but it's cut down by standard tokenizer.  
Now try to query, using the same analyzer -  
[https://gist.github.com/1404391#file\_query.json](https://gist.github.com/1404391#file_query.json) with no luck. IMHO it's  
because this hyphen is treated as lucene "minus". Escaping text with quotes  
gives proper results -  
[https://gist.github.com/1404391#file\_query\_with\_quotes.json](https://gist.github.com/1404391#file_query_with_quotes.json) .

Regards,  
Alexandr Vasilenko

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [November 30, 2011, 9:30am UTC](https://discuss.elastic.co/t/hyphens-in-query-string/6006/2 "2011-11-30T09:30:18Z")

</div>

I think the lucene query string parser works as this, why not  
implement it yourself on the client side?

Do you need the query\_string query at all - why not use the term query  
(and index:no) if you always query the full string (or describe what  
you need)?

Regards,  
Peter.

On 29 Nov., 12:00, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:

> Hello,
> 
> Is it possible to consider hyphen (separate by spaces) in query\_string as a  
> hyphen, rather than lucene "minus" (like explained in lucenehttp://lucene.apache.org/java/3\_4\_0/queryparsersyntax.html#-)?E.g.  
> consider it as "minus", when it's followed by the word, not space.
> 
> Reproduce:  
> Consider following mapping -[query\_all with hyphens · GitHub](https://gist.github.com/1404391#file_mapping.jsonand) contenthttps://gist.github.com/1404391#file\_content.json. Address contains  
> hyphen, but it's cut down by standard tokenizer.  
> Now try to query, using the same analyzer -[query\_all with hyphens · GitHub](https://gist.github.com/1404391#file_query.jsonwith) no luck. IMHO it's  
> because this hyphen is treated as lucene "minus". Escaping text with quotes  
> gives proper results -[query\_all with hyphens · GitHub](https://gist.github.com/1404391#file_query_with_quotes.json).
> 
> Regards,  
> Alexandr Vasilenko

---

<div class="post-metadata">

**Author:** ![avasilenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avasilenko/32/2901_2.png) [@avasilenko](https://discuss.elastic.co/u/avasilenko)\
**Post date:** [November 30, 2011, 9:50am UTC](https://discuss.elastic.co/t/hyphens-in-query-string/6006/3 "2011-11-30T09:50:55Z")

</div>

Hello Peter,

Yes, I need query\_string, because it's used as search input in client. Term  
and exact match is preferred, but client doesn't support it now and I was  
looking for solution on server side, specifically in ES.  
But anyway I force client devs to use term instead :).

Thanks,  
Alexandr Vasilenko

2011/11/30 Karussell [tableyourtime@googlemail.com](mailto:tableyourtime@googlemail.com)

> I think the lucene query string parser works as this, why not  
> implement it yourself on the client side?
> 
> Do you need the query\_string query at all - why not use the term query  
> (and index:no) if you always query the full string (or describe what  
> you need)?
> 
> Regards,  
> Peter.
> 
> On 29 Nov., 12:00, Alex Vasilenko [aa.vasile...@gmail.com](mailto:aa.vasile...@gmail.com) wrote:
> 
> > Hello,
> > 
> > Is it possible to consider hyphen (separate by spaces) in query\_string  
> > as a  
> > hyphen, rather than lucene "minus" (like explained in lucenehttp://  
> > [Apache Lucene - Query Parser Syntax](http://lucene.apache.org/java/3_4_0/queryparsersyntax.html#-))?E.g.  
> > consider it as "minus", when it's followed by the word, not space.
> > 
> > Reproduce:  
> > Consider following mapping -  
> > [query\_all with hyphens · GitHub](https://gist.github.com/1404391#file_mapping.jsonand) contenthttps://  
> > [query\_all with hyphens · GitHub](http://gist.github.com/1404391#file_content.json). Address contains  
> > hyphen, but it's cut down by standard tokenizer.  
> > Now try to query, using the same analyzer -  
> > [query\_all with hyphens · GitHub](https://gist.github.com/1404391#file_query.jsonwith) no luck. IMHO it's  
> > because this hyphen is treated as lucene "minus". Escaping text with  
> > quotes  
> > gives proper results -  
> > [query\_all with hyphens · GitHub](https://gist.github.com/1404391#file_query_with_quotes.json).
> > 
> > Regards,  
> > Alexandr Vasilenko

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:46am UTC](https://discuss.elastic.co/t/hyphens-in-query-string/6006/4 "2017-07-06T03:46:57Z")

</div>


