Filtered query not working

Hi,
I am a newbie to ES. Can someone tell, what i could be doing wrong in this
query -

curl -XGET 'http://localhost:920/twitter/_search?pretty=true' -d '
{
"fields" : ["name","screen_name","followers_count"],
"query" : {
"filtered" : {
"query" : { "matchAll" : {} },
"filter" : { "range" : {
"followers_count" : { "from" : 100, "to" : 10000 }
}
}
}
}
}'
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}

i have 2 elements in my index -
curl -XGET 'http://localhost:920/twitter/_search?pretty=true' -d '
{
"query" : { "matchAll" : {} } }'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "twitter",
"_type" : "user",
"_id" : "kimchy",
"_score" : 1.0, "_source" : { "name" : "Shay Banon" }
}, {
"_index" : "twitter",
"_type" : "audience",
"_id" : "18142273",
"_score" : 1.0, "_source" :
{"twitter_id":"2953","screen_name":"Lamoureux71","name":"Charles
Lamoureux","location":"San Clemente CA","bio":"Married father of twins,
working in the automotive
industry.","followers_count":401,"friends_count":854,"statuses_count":836,"listed_count":12}
} ]
}
}

I did some more investigation and it seems ES is treating my integer fields
as string fields and attempting string filter/comparison. e.g. this query
works fine -
curl -XGET 'http://localhost:920/twitter/audience/_search?pretty=true' -d '
{ query : { range : { followers_count : { from : 100, to : 50000 } } } }'
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "twitter",
"_type" : "audience",
"_id" : "18142273",
"_score" : 1.0, "_source" :
{"twitter_id":"2953","screen_name":"Lamoureux71","name":"Charles
Lamoureux","location":"San Clemente CA","bio":"Married father of twins,
working in the automotive
industry.","followers_count":401,"friends_count":854,"statuses_count":836,"listed_count":12}
} ]
}
}

i am wondering where am i going wrong?
this is how i added the entry to ES -
IndexRequestBuilder irb = client.prepareIndex("twitter",
"audience", "18142273")
.setSource(jsonBuilder()
.startObject()
.field("twitter_id", "2953")
.field("screen_name", "Lamoureux71")
.field("name", "Charles Lamoureux")
.field("location", "San Clemente CA")
.field("bio", "Married father of twins, working in
the automotive industry.")
.field("followers_count", 401)
.field("friends_count", 854)
.field("statuses_count", 836)
.field("listed_count", 12)
.endObject()
)
.execute()
.actionGet();

thanks

On Sun, Feb 12, 2012 at 11:54 PM, T Vinod Gupta tvinod@readypulse.comwrote:

Hi,
I am a newbie to ES. Can someone tell, what i could be doing wrong in this
query -

curl -XGET 'http://localhost:920/twitter/_search?pretty=true' -d '
{
"fields" : ["name","screen_name","followers_count"],
"query" : {
"filtered" : {
"query" : { "matchAll" : {} },
"filter" : { "range" : {
"followers_count" : { "from" : 100, "to" : 10000 }
}
}
}
}
}'
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" :
}

i have 2 elements in my index -
curl -XGET 'http://localhost:920/twitter/_search?pretty=true' -d '
{
"query" : { "matchAll" : {} } }'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "twitter",
"_type" : "user",
"_id" : "kimchy",
"_score" : 1.0, "_source" : { "name" : "Shay Banon" }
}, {
"_index" : "twitter",
"_type" : "audience",
"_id" : "18142273",
"_score" : 1.0, "_source" :
{"twitter_id":"2953","screen_name":"Lamoureux71","name":"Charles
Lamoureux","location":"San Clemente CA","bio":"Married father of twins,
working in the automotive
industry.","followers_count":401,"friends_count":854,"statuses_count":836,"listed_count":12}
} ]
}
}

Hi, you would need to post (use gist) your mappings to understand what
exactly is going on.

Are you using dynamic mappings or did you predefine your mappings? If
you are using dynamic mappings and the type was declared as a string
in JSON (surrounded by quotes), then Elasticsearch will always treat
that field as a string.

--
Ivan

On Mon, Feb 13, 2012 at 7:39 AM, T Vinod Gupta tvinod@readypulse.com wrote:

I did some more investigation and it seems ES is treating my integer fields
as string fields and attempting string filter/comparison. e.g. this query
works fine -
curl -XGET 'http://localhost:920/twitter/audience/_search?pretty=true' -d '
{ query : { range : { followers_count : { from : 100, to : 50000 } } } }'
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "twitter",
"_type" : "audience",
"_id" : "18142273",
"_score" : 1.0, "_source" :
{"twitter_id":"2953","screen_name":"Lamoureux71","name":"Charles
Lamoureux","location":"San Clemente CA","bio":"Married father of twins,
working in the automotive
industry.","followers_count":401,"friends_count":854,"statuses_count":836,"listed_count":12}
} ]
}
}

i am wondering where am i going wrong?
this is how i added the entry to ES -
IndexRequestBuilder irb = client.prepareIndex("twitter", "audience",
"18142273")
.setSource(jsonBuilder()
.startObject()
.field("twitter_id", "2953")
.field("screen_name", "Lamoureux71")
.field("name", "Charles Lamoureux")
.field("location", "San Clemente CA")
.field("bio", "Married father of twins, working in
the automotive industry.")
.field("followers_count", 401)
.field("friends_count", 854)
.field("statuses_count", 836)
.field("listed_count", 12)
.endObject()
)
.execute()
.actionGet();

thanks

On Sun, Feb 12, 2012 at 11:54 PM, T Vinod Gupta tvinod@readypulse.com
wrote:

Hi,
I am a newbie to ES. Can someone tell, what i could be doing wrong in this
query -

curl -XGET 'http://localhost:920/twitter/_search?pretty=true' -d '
{
"fields" : ["name","screen_name","followers_count"],
"query" : {
"filtered" : {
"query" : { "matchAll" : {} },
"filter" : { "range" : {
"followers_count" : { "from" : 100, "to" : 10000 }
}
}
}
}
}'
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" :
}

i have 2 elements in my index -
curl -XGET 'http://localhost:920/twitter/_search?pretty=true' -d '
{
"query" : { "matchAll" : {} } }'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "twitter",
"_type" : "user",
"_id" : "kimchy",
"_score" : 1.0, "_source" : { "name" : "Shay Banon" }
}, {
"_index" : "twitter",
"_type" : "audience",
"_id" : "18142273",
"_score" : 1.0, "_source" :
{"twitter_id":"2953","screen_name":"Lamoureux71","name":"Charles
Lamoureux","location":"San Clemente CA","bio":"Married father of twins,
working in the automotive
industry.","followers_count":401,"friends_count":854,"statuses_count":836,"listed_count":12}
} ]
}
}

Yea, as Ivan suggested, make sure you did not, by mistake, indexed the first json in that index with a string for the numeric value, in this case, it will be used as a string. You can use the get mapping API to see what types are actually used for the dynamic mappings derived from your data.

On Monday, February 13, 2012 at 8:29 PM, Ivan Brusic wrote:

Hi, you would need to post (use gist) your mappings to understand what
exactly is going on.

Are you using dynamic mappings or did you predefine your mappings? If
you are using dynamic mappings and the type was declared as a string
in JSON (surrounded by quotes), then Elasticsearch will always treat
that field as a string.

--
Ivan

On Mon, Feb 13, 2012 at 7:39 AM, T Vinod Gupta <tvinod@readypulse.com (mailto:tvinod@readypulse.com)> wrote:

I did some more investigation and it seems ES is treating my integer fields
as string fields and attempting string filter/comparison. e.g. this query
works fine -
curl -XGET 'http://localhost:920/twitter/audience/_search?pretty=true' -d '
{ query : { range : { followers_count : { from : 100, to : 50000 } } } }'
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "twitter",
"_type" : "audience",
"_id" : "18142273",
"_score" : 1.0, "_source" :
{"twitter_id":"2953","screen_name":"Lamoureux71","name":"Charles
Lamoureux","location":"San Clemente CA","bio":"Married father of twins,
working in the automotive
industry.","followers_count":401,"friends_count":854,"statuses_count":836,"listed_count":12}
} ]
}
}

i am wondering where am i going wrong?
this is how i added the entry to ES -
IndexRequestBuilder irb = client.prepareIndex("twitter", "audience",
"18142273")
.setSource(jsonBuilder()
.startObject()
.field("twitter_id", "2953")
.field("screen_name", "Lamoureux71")
.field("name", "Charles Lamoureux")
.field("location", "San Clemente CA")
.field("bio", "Married father of twins, working in
the automotive industry.")
.field("followers_count", 401)
.field("friends_count", 854)
.field("statuses_count", 836)
.field("listed_count", 12)
.endObject()
)
.execute()
.actionGet();

thanks

On Sun, Feb 12, 2012 at 11:54 PM, T Vinod Gupta <tvinod@readypulse.com (mailto:tvinod@readypulse.com)>
wrote:

Hi,
I am a newbie to ES. Can someone tell, what i could be doing wrong in this
query -

curl -XGET 'http://localhost:920/twitter/_search?pretty=true' -d '
{
"fields" : ["name","screen_name","followers_count"],
"query" : {
"filtered" : {
"query" : { "matchAll" : {} },
"filter" : { "range" : {
"followers_count" : { "from" : 100, "to" : 10000 }
}
}
}
}
}'
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" :
}

i have 2 elements in my index -
curl -XGET 'http://localhost:920/twitter/_search?pretty=true' -d '
{
"query" : { "matchAll" : {} } }'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "twitter",
"_type" : "user",
"_id" : "kimchy",
"_score" : 1.0, "_source" : { "name" : "Shay Banon" }
}, {
"_index" : "twitter",
"_type" : "audience",
"_id" : "18142273",
"_score" : 1.0, "_source" :
{"twitter_id":"2953","screen_name":"Lamoureux71","name":"Charles
Lamoureux","location":"San Clemente CA","bio":"Married father of twins,
working in the automotive
industry.","followers_count":401,"friends_count":854,"statuses_count":836,"listed_count":12}
} ]
}
}