# Unexpected results when search phrase contains angular brackets

**URL:** <https://discuss.elastic.co/t/unexpected-results-when-search-phrase-contains-angular-brackets/12821>\
**Category:** Elasticsearch\
**Created:** [July 17, 2013, 9:31am UTC](https://discuss.elastic.co/t/unexpected-results-when-search-phrase-contains-angular-brackets/12821 "2013-07-17T09:31:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![imdhmd](https://avatars.discourse-cdn.com/v4/letter/i/d07c76/32.png) [@imdhmd](https://discuss.elastic.co/u/imdhmd)\
**Post date:** [July 17, 2013, 9:31am UTC](https://discuss.elastic.co/t/unexpected-results-when-search-phrase-contains-angular-brackets/12821/1 "2013-07-17T09:31:32Z")

</div>

Hello ppl,

I am using:  
ES 0.20.6

I created an index "some" and a type "type", with default settings,  
analyzers and mapping

I have indexed the following two docs:  
{"annotationText": "here are for you"}

{"annotationText": "come as you are"}

I issue the following search:  
{ "query": {  
"query\_string": {  
"query" : ""  
}  
},  
"highlight": {  
"fields": {  
"annotationText": {  
}  
}  
}  
}

I get the following results:  
{  
"\_source": {  
"annotationText": "here are for you"  
},  
"highlight": {  
"annotationText": [  
"_here_ are \<_some_\> for you"  
]  
}  
},  
{  
"\_source": {  
"annotationText": "come as you are"  
},  
"highlight": {  
"annotationText": [  
"_come_ as you are"  
]  
}  
}

So you see search for "" resulted in totally irrelevant results.  
Escaping \< and \> does not help. It results in error saying unrecognised  
escape character.

What is happening here? How can i issue search query which contain \< or \>  
and get sane results?

- Imdad

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Guilherme\_Guitte](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guilherme_guitte/32/2221_2.png) [@Guilherme\_Guitte](https://discuss.elastic.co/u/Guilherme_Guitte)\
**Post date:** [July 17, 2013, 11:35am UTC](https://discuss.elastic.co/t/unexpected-results-when-search-phrase-contains-angular-brackets/12821/2 "2013-07-17T11:35:33Z")

</div>

Could you post your mapping and settings please?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Boaz\_Leskes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boaz_leskes/32/723_2.png) [@Boaz\_Leskes](https://discuss.elastic.co/u/Boaz_Leskes)\
**Post date:** [July 17, 2013, 4:41pm UTC](https://discuss.elastic.co/t/unexpected-results-when-search-phrase-contains-angular-brackets/12821/3 "2013-07-17T16:41:11Z")

</div>

Hi imdad,

The \< sign in the beginning is interpreted by Lucene as a range query and  
it becomes and open ended range query [:some] for field \_all. I didn't  
spend too much time looking at the code but at first glance I don't see an  
escaping possibility. To be honest, I think you will be much better off  
with the match query of elasticsearch - it treats the input as text and  
doesn't parse it for any operator. This works for me:

{  
"query": {  
"match": {  
"annotationText": ""  
}  
},  
"highlight": {  
"fields": {  
"annotationText": {}  
}  
}  
}

Cheers,  
Boaz

On Wednesday, July 17, 2013 1:35:33 PM UTC+2, Guilherme Guitte wrote:

> Could you post your mapping and settings please?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:25am UTC](https://discuss.elastic.co/t/unexpected-results-when-search-phrase-contains-angular-brackets/12821/4 "2017-07-06T02:25:55Z")

</div>


