# Query\_string query that contains \< and \> symbols

**URL:** <https://discuss.elastic.co/t/query-string-query-that-contains-and-symbols/19140>\
**Category:** Elasticsearch\
**Created:** [August 7, 2014, 3:27pm UTC](https://discuss.elastic.co/t/query-string-query-that-contains-and-symbols/19140 "2014-08-07T15:27:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tihomir\_Lichev1](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Tihomir\_Lichev1](https://discuss.elastic.co/u/Tihomir_Lichev1)\
**Post date:** [August 7, 2014, 3:27pm UTC](https://discuss.elastic.co/t/query-string-query-that-contains-and-symbols/19140/1 "2014-08-07T15:27:08Z")

</div>

Hello,  
I recently discovered very interesting problem

The analyzer is _whitespace:_  
{  
"mappings": {  
"test": {  
"properties": {  
"title": {  
"analyzer": "whitespace",  
"type": "string"  
},  
"description": {  
"analyzer": "whitespace",  
"type": "string"  
}  
}  
}  
}  
}

I have 3 documents with the following content:  
{  
"id": 1,  
"title" : "testing123",  
"description" : "a description"  
}  
{  
"id": 2,  
"title" : "testing \>end",  
"description" : "another description"  
}  
{  
"id": 3,  
"title" : "testing \<end",  
"description" : "another description"  
}

Then I did the following search queries:  
{  
"query": {

```
"bool": {
  "should": [
    {
      "query_string": {
        "query": ">end",
        "fields": [
          "title"
        ]
      }
    }
  ]
}

```

}  
}

RESULT: 3 hits (all docs) - wrong  
EXPLAIN description: "ConstantScore(title:{end TO \*]), product of:"

{  
"query": {

```
"bool": {
  "should": [
    {
      "query_string": {
        "query": "<end",
        "fields": [
          "title"
        ]
      }
    }
  ]
}

```

}  
}

RESULT: 3 hits (all docs) - wrong  
EXPLAIN description: "ConstantScore(title:[\* TO end}), product of:"

{  
"query": {

```
"bool": {
  "should": [
    {
      "query_string": {
        "query": "end",
        "fields": [
          "title"
        ]
      }
    }
  ]
}

```

}  
}

RESULT: 0 hits (correct!)

I tried to escape "\<" and "\>" in the query, but no success

Search for \< and \> in the elasticsearch and lucene docs - also no luck.  
Obvoiusly they are recognized as range operators, but I want to use them  
also as normal text symbols.  
Is there any way to escape them properly ?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6388d7d4-d14a-4e6e-b09b-67860ccbb574%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6388d7d4-d14a-4e6e-b09b-67860ccbb574%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Tihomir\_Lichev1](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Tihomir\_Lichev1](https://discuss.elastic.co/u/Tihomir_Lichev1)\
**Post date:** [August 12, 2014, 8:50am UTC](https://discuss.elastic.co/t/query-string-query-that-contains-and-symbols/19140/2 "2014-08-12T08:50:05Z")

</div>

Does anyone have an idea hot to escape \< and \> in a query ???

07 август 2014, четвъртък, 18:27:08 UTC+3, Tihomir Lichev написа:

> Hello,  
> I recently discovered very interesting problem
> 
> The analyzer is _whitespace:_  
> {  
> "mappings": {  
> "test": {  
> "properties": {  
> "title": {  
> "analyzer": "whitespace",  
> "type": "string"  
> },  
> "description": {  
> "analyzer": "whitespace",  
> "type": "string"  
> }  
> }  
> }  
> }  
> }
> 
> I have 3 documents with the following content:  
> {  
> "id": 1,  
> "title" : "testing123",  
> "description" : "a description"  
> }  
> {  
> "id": 2,  
> "title" : "testing \>end",  
> "description" : "another description"  
> }  
> {  
> "id": 3,  
> "title" : "testing \<end",  
> "description" : "another description"  
> }
> 
> Then I did the following search queries:  
> {  
> "query": {
> 
> ```
> "bool": {
> "should": [
> {
> "query_string": {
> "query": ">end",
> "fields": [
> "title"
> ]
> }
> }
> ]
> }
> 
> ```
> 
> }  
> }
> 
> RESULT: 3 hits (all docs) - wrong  
> EXPLAIN description: "ConstantScore(title:{end TO \*]), product of:"
> 
> {  
> "query": {
> 
> ```
> "bool": {
> "should": [
> {
> "query_string": {
> "query": "<end",
> "fields": [
> "title"
> ]
> }
> }
> ]
> }
> 
> ```
> 
> }  
> }
> 
> RESULT: 3 hits (all docs) - wrong  
> EXPLAIN description: "ConstantScore(title:[\* TO end}), product of:"
> 
> {  
> "query": {
> 
> ```
> "bool": {
> "should": [
> {
> "query_string": {
> "query": "end",
> "fields": [
> "title"
> ]
> }
> }
> ]
> }
> 
> ```
> 
> }  
> }
> 
> RESULT: 0 hits (correct!)
> 
> I tried to escape "\<" and "\>" in the query, but no success
> 
> Search for \< and \> in the elasticsearch and lucene docs - also no luck.  
> Obvoiusly they are recognized as range operators, but I want to use them  
> also as normal text symbols.  
> Is there any way to escape them properly ?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [August 12, 2014, 8:56am UTC](https://discuss.elastic.co/t/query-string-query-that-contains-and-symbols/19140/3 "2014-08-12T08:56:26Z")

</div>

This is not a problem of escape.

Always use "match" query. Never use "query\_string".

Jörg

On Tue, Aug 12, 2014 at 10:50 AM, Tihomir Lichev [shoteff@gmail.com](mailto:shoteff@gmail.com) wrote:

> Does anyone have an idea hot to escape \< and \> in a query ???
> 
> 07 август 2014, четвъртък, 18:27:08 UTC+3, Tihomir Lichev написа:
> 
> > Hello,  
> > I recently discovered very interesting problem
> > 
> > The analyzer is _whitespace:_  
> > {  
> > "mappings": {  
> > "test": {  
> > "properties": {  
> > "title": {  
> > "analyzer": "whitespace",  
> > "type": "string"  
> > },  
> > "description": {  
> > "analyzer": "whitespace",  
> > "type": "string"  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > I have 3 documents with the following content:  
> > {  
> > "id": 1,  
> > "title" : "testing123",  
> > "description" : "a description"  
> > }  
> > {  
> > "id": 2,  
> > "title" : "testing \>end",  
> > "description" : "another description"  
> > }  
> > {  
> > "id": 3,  
> > "title" : "testing \<end",  
> > "description" : "another description"  
> > }
> > 
> > Then I did the following search queries:  
> > {  
> > "query": {
> > 
> > ```
> > "bool": {
> > "should": [
> > {
> > "query_string": {
> > "query": ">end",
> > "fields": [
> > "title"
> > ]
> > }
> > }
> > ]
> > }
> > 
> > ```
> > 
> > }  
> > }
> > 
> > RESULT: 3 hits (all docs) - wrong  
> > EXPLAIN description: "ConstantScore(title:{end TO \*]), product of:"
> > 
> > {  
> > "query": {
> > 
> > ```
> > "bool": {
> > "should": [
> > {
> > "query_string": {
> > "query": "<end",
> > "fields": [
> > "title"
> > ]
> > }
> > }
> > ]
> > }
> > 
> > ```
> > 
> > }  
> > }
> > 
> > RESULT: 3 hits (all docs) - wrong  
> > EXPLAIN description: "ConstantScore(title:[\* TO end}), product of:"
> > 
> > {  
> > "query": {
> > 
> > ```
> > "bool": {
> > "should": [
> > {
> > "query_string": {
> > "query": "end",
> > "fields": [
> > "title"
> > ]
> > }
> > }
> > ]
> > }
> > 
> > ```
> > 
> > }  
> > }
> > 
> > RESULT: 0 hits (correct!)
> > 
> > I tried to escape "\<" and "\>" in the query, but no success
> > 
> > Search for \< and \> in the elasticsearch and lucene docs - also no luck.  
> > Obvoiusly they are recognized as range operators, but I want to use them  
> > also as normal text symbols.  
> > Is there any way to escape them properly ?
> > 
> > --  
> > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEfEhK%3D-XWyy8kqRqN6\_ESNGa7U1uuowDmm37\_0%2BkXo0Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEfEhK%3D-XWyy8kqRqN6_ESNGa7U1uuowDmm37_0%2BkXo0Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Tihomir\_Lichev1](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Tihomir\_Lichev1](https://discuss.elastic.co/u/Tihomir_Lichev1)\
**Post date:** [August 12, 2014, 9:01am UTC](https://discuss.elastic.co/t/query-string-query-that-contains-and-symbols/19140/4 "2014-08-12T09:01:59Z")

</div>

I think I don't agree ...  
I'm using query\_string because I want to give the users the ability to use  
AND, OR +, - etc., out of the box.  
I'm able to escape all other symbols except \< and \>, and I can use them as  
part of the field content, also as part of the query like any regular  
letter.  
I dont understand why there is no way to escape those 2 symbols only. How  
they are different compared to the others ???

Tihomir

12 август 2014, вторник, 11:57:21 UTC+3, Jörg Prante написа:

> This is not a problem of escape.
> 
> Always use "match" query. Never use "query\_string".
> 
> Jörg
> 
> On Tue, Aug 12, 2014 at 10:50 AM, Tihomir Lichev \<[sho...@gmail.com](mailto:sho...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Does anyone have an idea hot to escape \< and \> in a query ???
> > 
> > 07 август 2014, четвъртък, 18:27:08 UTC+3, Tihomir Lichev написа:
> > 
> > > Hello,  
> > > I recently discovered very interesting problem
> > > 
> > > The analyzer is _whitespace:_  
> > > {  
> > > "mappings": {  
> > > "test": {  
> > > "properties": {  
> > > "title": {  
> > > "analyzer": "whitespace",  
> > > "type": "string"  
> > > },  
> > > "description": {  
> > > "analyzer": "whitespace",  
> > > "type": "string"  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > I have 3 documents with the following content:  
> > > {  
> > > "id": 1,  
> > > "title" : "testing123",  
> > > "description" : "a description"  
> > > }  
> > > {  
> > > "id": 2,  
> > > "title" : "testing \>end",  
> > > "description" : "another description"  
> > > }  
> > > {  
> > > "id": 3,  
> > > "title" : "testing \<end",  
> > > "description" : "another description"  
> > > }
> > > 
> > > Then I did the following search queries:  
> > > {  
> > > "query": {
> > > 
> > > ```
> > > "bool": {
> > > "should": [
> > > {
> > > "query_string": {
> > > "query": ">end",
> > > "fields": [
> > > "title"
> > > ]
> > > }
> > > }
> > > ]
> > > }
> > > 
> > > ```
> > > 
> > > }  
> > > }
> > > 
> > > RESULT: 3 hits (all docs) - wrong  
> > > EXPLAIN description: "ConstantScore(title:{end TO \*]), product of:"
> > > 
> > > {  
> > > "query": {
> > > 
> > > ```
> > > "bool": {
> > > "should": [
> > > {
> > > "query_string": {
> > > "query": "<end",
> > > "fields": [
> > > "title"
> > > ]
> > > }
> > > }
> > > ]
> > > }
> > > 
> > > ```
> > > 
> > > }  
> > > }
> > > 
> > > RESULT: 3 hits (all docs) - wrong  
> > > EXPLAIN description: "ConstantScore(title:[\* TO end}), product of:"
> > > 
> > > {  
> > > "query": {
> > > 
> > > ```
> > > "bool": {
> > > "should": [
> > > {
> > > "query_string": {
> > > "query": "end",
> > > "fields": [
> > > "title"
> > > ]
> > > }
> > > }
> > > ]
> > > }
> > > 
> > > ```
> > > 
> > > }  
> > > }
> > > 
> > > RESULT: 0 hits (correct!)
> > > 
> > > I tried to escape "\<" and "\>" in the query, but no success
> > > 
> > > Search for \< and \> in the elasticsearch and lucene docs - also no luck.  
> > > Obvoiusly they are recognized as range operators, but I want to use them  
> > > also as normal text symbols.  
> > > Is there any way to escape them properly ?
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [August 12, 2014, 9:07am UTC](https://discuss.elastic.co/t/query-string-query-that-contains-and-symbols/19140/5 "2014-08-12T09:07:51Z")

</div>

Once again, it is not related to "escaping".

Why don't you use simple query\_string?

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

It wraps the crappy query\_string into "match" query, correctly analyzed and  
parsed to Elasticsearch settings, which query\_string is not always able to.  
And it provides boolean clauses.

Jörg

Examples:

POST /test/\_search  
{  
"query" : {  
"simple\_query\_string" : {  
"title" : {  
"query" : "\>end"  
}  
}  
}  
}

POST /test/\_search  
{  
"query" : {  
"simple\_query\_string" : {  
"title" : {  
"query" : " testing and \>end"  
}  
}  
}  
}

On Tue, Aug 12, 2014 at 11:01 AM, Tihomir Lichev [shoteff@gmail.com](mailto:shoteff@gmail.com) wrote:

> I think I don't agree ...  
> I'm using query\_string because I want to give the users the ability to use  
> AND, OR +, - etc., out of the box.  
> I'm able to escape all other symbols except \< and \>, and I can use them as  
> part of the field content, also as part of the query like any regular  
> letter.  
> I dont understand why there is no way to escape those 2 symbols only. How  
> they are different compared to the others ???
> 
> Tihomir
> 
> 12 август 2014, вторник, 11:57:21 UTC+3, Jörg Prante написа:
> 
> > This is not a problem of escape.
> > 
> > Always use "match" query. Never use "query\_string".
> > 
> > Jörg
> > 
> > On Tue, Aug 12, 2014 at 10:50 AM, Tihomir Lichev [sho...@gmail.com](mailto:sho...@gmail.com)  
> > wrote:
> > 
> > > Does anyone have an idea hot to escape \< and \> in a query ???
> > > 
> > > 07 август 2014, четвъртък, 18:27:08 UTC+3, Tihomir Lichev написа:
> > > 
> > > > Hello,  
> > > > I recently discovered very interesting problem
> > > > 
> > > > The analyzer is _whitespace:_  
> > > > {  
> > > > "mappings": {  
> > > > "test": {  
> > > > "properties": {  
> > > > "title": {  
> > > > "analyzer": "whitespace",  
> > > > "type": "string"  
> > > > },  
> > > > "description": {  
> > > > "analyzer": "whitespace",  
> > > > "type": "string"  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > I have 3 documents with the following content:  
> > > > {  
> > > > "id": 1,  
> > > > "title" : "testing123",  
> > > > "description" : "a description"  
> > > > }  
> > > > {  
> > > > "id": 2,  
> > > > "title" : "testing \>end",  
> > > > "description" : "another description"  
> > > > }  
> > > > {  
> > > > "id": 3,  
> > > > "title" : "testing \<end",  
> > > > "description" : "another description"  
> > > > }
> > > > 
> > > > Then I did the following search queries:  
> > > > {  
> > > > "query": {
> > > > 
> > > > ```
> > > > "bool": {
> > > > "should": [
> > > > {
> > > > "query_string": {
> > > > "query": ">end",
> > > > "fields": [
> > > > "title"
> > > > ]
> > > > }
> > > > }
> > > > ]
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > }  
> > > > }
> > > > 
> > > > RESULT: 3 hits (all docs) - wrong  
> > > > EXPLAIN description: "ConstantScore(title:{end TO \*]), product of:"
> > > > 
> > > > {  
> > > > "query": {
> > > > 
> > > > ```
> > > > "bool": {
> > > > "should": [
> > > > {
> > > > "query_string": {
> > > > "query": "<end",
> > > > "fields": [
> > > > "title"
> > > > ]
> > > > }
> > > > }
> > > > ]
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > }  
> > > > }
> > > > 
> > > > RESULT: 3 hits (all docs) - wrong  
> > > > EXPLAIN description: "ConstantScore(title:[\* TO end}), product of:"
> > > > 
> > > > {  
> > > > "query": {
> > > > 
> > > > ```
> > > > "bool": {
> > > > "should": [
> > > > {
> > > > "query_string": {
> > > > "query": "end",
> > > > "fields": [
> > > > "title"
> > > > ]
> > > > }
> > > > }
> > > > ]
> > > > }
> > > > 
> > > > ```
> > > > 
> > > > }  
> > > > }
> > > > 
> > > > RESULT: 0 hits (correct!)
> > > > 
> > > > I tried to escape "\<" and "\>" in the query, but no success
> > > > 
> > > > Search for \< and \> in the elasticsearch and lucene docs - also no luck.  
> > > > Obvoiusly they are recognized as range operators, but I want to use them  
> > > > also as normal text symbols.  
> > > > Is there any way to escape them properly ?
> > > > 
> > > > --  
> > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%  
> > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > [https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > .
> > > 
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEqhNz\_J\_avq-m3QXY4aDSwvQMOL%3DCDLAQKoJHsMWNoZg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEqhNz_J_avq-m3QXY4aDSwvQMOL%3DCDLAQKoJHsMWNoZg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Tihomir\_Lichev1](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Tihomir\_Lichev1](https://discuss.elastic.co/u/Tihomir_Lichev1)\
**Post date:** [August 12, 2014, 9:21am UTC](https://discuss.elastic.co/t/query-string-query-that-contains-and-symbols/19140/6 "2014-08-12T09:21:37Z")

</div>

That makes much more sense 🙂  
Thanks, it works now!  
And somewhere in the query\_string docs should be mentioned that  
simple\_query\_string should be preferred in where applicable 😛

12 август 2014, вторник, 12:07:58 UTC+3, Jörg Prante написа:

> Once again, it is not related to "escaping".
> 
> Why don't you use simple query\_string?
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html)
> 
> It wraps the crappy query\_string into "match" query, correctly analyzed  
> and parsed to Elasticsearch settings, which query\_string is not always able  
> to. And it provides boolean clauses.
> 
> Jörg
> 
> Examples:
> 
> POST /test/\_search  
> {  
> "query" : {  
> "simple\_query\_string" : {  
> "title" : {  
> "query" : "\>end"  
> }  
> }  
> }  
> }
> 
> POST /test/\_search  
> {  
> "query" : {  
> "simple\_query\_string" : {  
> "title" : {  
> "query" : " testing and \>end"  
> }  
> }  
> }  
> }
> 
> On Tue, Aug 12, 2014 at 11:01 AM, Tihomir Lichev \<[sho...@gmail.com](mailto:sho...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > I think I don't agree ...  
> > I'm using query\_string because I want to give the users the ability to  
> > use AND, OR +, - etc., out of the box.  
> > I'm able to escape all other symbols except \< and \>, and I can use them  
> > as part of the field content, also as part of the query like any regular  
> > letter.  
> > I dont understand why there is no way to escape those 2 symbols only. How  
> > they are different compared to the others ???
> > 
> > Tihomir
> > 
> > 12 август 2014, вторник, 11:57:21 UTC+3, Jörg Prante написа:
> > 
> > > This is not a problem of escape.
> > > 
> > > Always use "match" query. Never use "query\_string".
> > > 
> > > Jörg
> > > 
> > > On Tue, Aug 12, 2014 at 10:50 AM, Tihomir Lichev [sho...@gmail.com](mailto:sho...@gmail.com)  
> > > wrote:
> > > 
> > > > Does anyone have an idea hot to escape \< and \> in a query ???
> > > > 
> > > > 07 август 2014, четвъртък, 18:27:08 UTC+3, Tihomir Lichev написа:
> > > > 
> > > > > Hello,  
> > > > > I recently discovered very interesting problem
> > > > > 
> > > > > The analyzer is _whitespace:_  
> > > > > {  
> > > > > "mappings": {  
> > > > > "test": {  
> > > > > "properties": {  
> > > > > "title": {  
> > > > > "analyzer": "whitespace",  
> > > > > "type": "string"  
> > > > > },  
> > > > > "description": {  
> > > > > "analyzer": "whitespace",  
> > > > > "type": "string"  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }  
> > > > > }
> > > > > 
> > > > > I have 3 documents with the following content:  
> > > > > {  
> > > > > "id": 1,  
> > > > > "title" : "testing123",  
> > > > > "description" : "a description"  
> > > > > }  
> > > > > {  
> > > > > "id": 2,  
> > > > > "title" : "testing \>end",  
> > > > > "description" : "another description"  
> > > > > }  
> > > > > {  
> > > > > "id": 3,  
> > > > > "title" : "testing \<end",  
> > > > > "description" : "another description"  
> > > > > }
> > > > > 
> > > > > Then I did the following search queries:  
> > > > > {  
> > > > > "query": {
> > > > > 
> > > > > ```
> > > > > "bool": {
> > > > > "should": [
> > > > > {
> > > > > "query_string": {
> > > > > "query": ">end",
> > > > > "fields": [
> > > > > "title"
> > > > > ]
> > > > > }
> > > > > }
> > > > > ]
> > > > > }
> > > > > 
> > > > > ```
> > > > > 
> > > > > }  
> > > > > }
> > > > > 
> > > > > RESULT: 3 hits (all docs) - wrong  
> > > > > EXPLAIN description: "ConstantScore(title:{end TO \*]), product of:"
> > > > > 
> > > > > {  
> > > > > "query": {
> > > > > 
> > > > > ```
> > > > > "bool": {
> > > > > "should": [
> > > > > {
> > > > > "query_string": {
> > > > > "query": "<end",
> > > > > "fields": [
> > > > > "title"
> > > > > ]
> > > > > }
> > > > > }
> > > > > ]
> > > > > }
> > > > > 
> > > > > ```
> > > > > 
> > > > > }  
> > > > > }
> > > > > 
> > > > > RESULT: 3 hits (all docs) - wrong  
> > > > > EXPLAIN description: "ConstantScore(title:[\* TO end}), product of:"
> > > > > 
> > > > > {  
> > > > > "query": {
> > > > > 
> > > > > ```
> > > > > "bool": {
> > > > > "should": [
> > > > > {
> > > > > "query_string": {
> > > > > "query": "end",
> > > > > "fields": [
> > > > > "title"
> > > > > ]
> > > > > }
> > > > > }
> > > > > ]
> > > > > }
> > > > > 
> > > > > ```
> > > > > 
> > > > > }  
> > > > > }
> > > > > 
> > > > > RESULT: 0 hits (correct!)
> > > > > 
> > > > > I tried to escape "\<" and "\>" in the query, but no success
> > > > > 
> > > > > Search for \< and \> in the elasticsearch and lucene docs - also no  
> > > > > luck. Obvoiusly they are recognized as range operators, but I want to use  
> > > > > them also as normal text symbols.  
> > > > > Is there any way to escape them properly ?
> > > > > 
> > > > > --  
> > > > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > > > msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%  
> > > > > [40googlegroups.com](http://40googlegroups.com)  
> > > > > [https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9fee6a55-b3ff-4192-9329-4e5f6fead45e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > > > .
> > > > 
> > > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/d6bb86ed-111b-4909-a918-e8ae797579da%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ad07f829-f604-4d17-9e17-e53f1f768541%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ad07f829-f604-4d17-9e17-e53f1f768541%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:09am UTC](https://discuss.elastic.co/t/query-string-query-that-contains-and-symbols/19140/7 "2017-07-06T01:09:16Z")

</div>


