Curious query_string results

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.
For more options, visit https://groups.google.com/groups/opt_out.

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 queryhttp://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.
For more options, visit https://groups.google.com/groups/opt_out.

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 :frowning:

chris

On Wed, Jul 3, 2013 at 9:57 AM, Luca Cavanna 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 queryhttp://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.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.