# Curious query\_string results

**URL:** <https://discuss.elastic.co/t/curious-query-string-results/12618>\
**Category:** Elasticsearch\
**Created:** [July 2, 2013, 2:25pm UTC](https://discuss.elastic.co/t/curious-query-string-results/12618 "2013-07-02T14:25:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_stevenson\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_stevenson_2/32/2257_2.png) [@chris\_stevenson\_2](https://discuss.elastic.co/u/chris_stevenson_2)\
**Post date:** [July 2, 2013, 2:25pm UTC](https://discuss.elastic.co/t/curious-query-string-results/12618/1 "2013-07-02T14:25:12Z")

</div>

Hi,

I have noticed if I use  
{  
"query" : {  
"query\_string" : {  
"query" : "userid \>= 100"  
}  
}  
}

then I get 125 results (correctly):  
hits: {

```
total: 125
max_score: 0.6850374
hits: [
    {
        _index: events
        _type: folderid
        _id: 66
        _source: {
            <snip>
            userid: 100
            type: ADDFOLDER
            organisationid: 100
            accountid: 400
        }
    }

```

However, if I use  
{  
"query" : {  
"query\_string" : {  
"query" : "userid \> 100"  
}  
}  
}  
ie, just removing the '=', I get 6 results, and the userid is exactly 100:  
hits: {

```
total: 6
max_score: 0.42181164
hits: [
    {
        _index: events
        _type: versionid
        _id: 66
        _source: {
            <snip>
            userid: 100
            type: ADDFOLDER
            organisationid: 100
            accountid: 400
        }
    }
    ...

```

As an aside, "userid\>=100" (no spaces) also just returns 6 results, with  
userid as 100.

Any clues as to what is going on would be appreciated!

thanks

chris

--  
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:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [July 3, 2013, 8:57am UTC](https://discuss.elastic.co/t/curious-query-string-results/12618/2 "2013-07-03T08:57:48Z")

</div>

Hi Chris,  
I don't think the syntax you're using is supported by the query\_string  
query. Other information that might be relevant: Did you define any mapping  
for the userid field? Is it analyzed?

It might be interesting for you to have a look at the explain output of  
your query to see what the query that gets executed on the lucene level  
looks like. You can enable it just adding the explain:true property to your  
search request.

If you want to execute a range query using the query\_string you should use  
this syntax: "userid:[100 TO \*]". But my next question is do you really  
need to use a query\_string? It turns out in most of the cases it's better  
to use a more specific query, like the range query[http://www.elasticsearch.org/guide/reference/query-dsl/range-query/](http://www.elasticsearch.org/guide/reference/query-dsl/range-query/)in your case rather than the query\_string, which is more powerful but can  
lead to issues in the parse phase.

On Tuesday, July 2, 2013 4:25:12 PM UTC+2, chris stevenson wrote:

> Hi,
> 
> I have noticed if I use  
> {  
> "query" : {  
> "query\_string" : {  
> "query" : "userid \>= 100"  
> }  
> }  
> }
> 
> then I get 125 results (correctly):  
> hits: {
> 
> ```
> total: 125
> max_score: 0.6850374
> hits: [
> {
> _index: events
> _type: folderid
> _id: 66
> _source: {
> <snip>
> userid: 100
> type: ADDFOLDER
> organisationid: 100
> accountid: 400
> }
> }
> 
> ```
> 
> However, if I use  
> {  
> "query" : {  
> "query\_string" : {  
> "query" : "userid \> 100"  
> }  
> }  
> }  
> ie, just removing the '=', I get 6 results, and the userid is exactly 100:  
> hits: {
> 
> ```
> total: 6
> max_score: 0.42181164
> hits: [
> {
> _index: events
> _type: versionid
> _id: 66
> _source: {
> <snip>
> userid: 100
> type: ADDFOLDER
> organisationid: 100
> accountid: 400
> }
> }
> ...
> 
> ```
> 
> As an aside, "userid\>=100" (no spaces) also just returns 6 results, with  
> userid as 100.
> 
> Any clues as to what is going on would be appreciated!
> 
> thanks
> 
> chris

--  
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:** ![chris\_stevenson\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_stevenson_2/32/2257_2.png) [@chris\_stevenson\_2](https://discuss.elastic.co/u/chris_stevenson_2)\
**Post date:** [July 3, 2013, 10:44am UTC](https://discuss.elastic.co/t/curious-query-string-results/12618/3 "2013-07-03T10:44:22Z")

</div>

Hi Luca,

Thanks for your reply, it was very helpful, and works beautifully.

I would love to use the range query, but am constrained by members of the  
team here ☹

chris

On Wed, Jul 3, 2013 at 9:57 AM, Luca Cavanna [cavannaluca@gmail.com](mailto:cavannaluca@gmail.com) wrote:

> Hi Chris,  
> I don't think the syntax you're using is supported by the query\_string  
> query. Other information that might be relevant: Did you define any mapping  
> for the userid field? Is it analyzed?
> 
> It might be interesting for you to have a look at the explain output of  
> your query to see what the query that gets executed on the lucene level  
> looks like. You can enable it just adding the explain:true property to your  
> search request.
> 
> If you want to execute a range query using the query\_string you should use  
> this syntax: "userid:[100 TO \*]". But my next question is do you really  
> need to use a query\_string? It turns out in most of the cases it's better  
> to use a more specific query, like the range query[http://www.elasticsearch.org/guide/reference/query-dsl/range-query/](http://www.elasticsearch.org/guide/reference/query-dsl/range-query/)in your case rather than the query\_string, which is more powerful but can  
> lead to issues in the parse phase.
> 
> On Tuesday, July 2, 2013 4:25:12 PM UTC+2, chris stevenson wrote:
> 
> > Hi,
> > 
> > I have noticed if I use  
> > {  
> > "query" : {  
> > "query\_string" : {  
> > "query" : "userid \>= 100"  
> > }  
> > }  
> > }
> > 
> > then I get 125 results (correctly):  
> > hits: {
> > 
> > ```
> > total: 125
> > max_score: 0.6850374
> > hits: [
> > {
> > _index: events
> > _type: folderid
> > _id: 66
> > _source: {
> > <snip>
> > userid: 100
> > type: ADDFOLDER
> > organisationid: 100
> > accountid: 400
> > }
> > }
> > 
> > ```
> > 
> > However, if I use  
> > {  
> > "query" : {  
> > "query\_string" : {  
> > "query" : "userid \> 100"  
> > }  
> > }  
> > }  
> > ie, just removing the '=', I get 6 results, and the userid is exactly  
> > 100:  
> > hits: {
> > 
> > ```
> > total: 6
> > max_score: 0.42181164
> > hits: [
> > {
> > _index: events
> > _type: versionid
> > _id: 66
> > _source: {
> > <snip>
> > userid: 100
> > type: ADDFOLDER
> > organisationid: 100
> > accountid: 400
> > }
> > }
> > ...
> > 
> > ```
> > 
> > As an aside, "userid\>=100" (no spaces) also just returns 6 results, with  
> > userid as 100.
> > 
> > Any clues as to what is going on would be appreciated!
> > 
> > thanks
> > 
> > chris
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/imSpSjcpnOQ/unsubscribe](https://groups.google.com/d/topic/elasticsearch/imSpSjcpnOQ/unsubscribe).  
> To unsubscribe from this group and all its topics, 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).

--  
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:28am UTC](https://discuss.elastic.co/t/curious-query-string-results/12618/4 "2017-07-06T02:28:28Z")

</div>

Closed on July 6, 2017, 2:28am UTC


