Multiple query terms

I am trying to to execute a query that does 3 things:

  1. returns gender = 0;
    AND
  2. returns bio = test
    AND
  3. is within 200 mi.

Here is my query:
{
"query" : {
"term": {
"gender":0, "bio": "test"
}
},
"filter" : {
"geo_distance" : {
"distance" : "200mi",
"pos" : {
"lat" : 40,
"lon" : 40
}
}
}
}

The geographic part works fine, so that's not the problem. The problem is
the 2nd term. It basically seems to disregard the 2nd term altogether. It
does only show gender = 0, but returns all gender =0, and doesn't care what
the value of bio is. Basically, I want to do an AND query with the
gender=0 and bio="test", however I'm not clear on how to execute that. I
see the AND operator in the filters, but I don't think I want to use it as
a filter, I think I want to use it in the query.

Thanks for your assistance.

--

hi ryano

not sure if this will help but I used query_string instead of term

curl -XGET 'http://localhost:9200/lists/list/_search' -d '{
"query":{
"query_string" : {
"query" : "(user:lu) AND ((horror AND movie) OR (horror OR movie))",
"analyzer":"stem"
}
}
}'

or you could try default_operator but not sure if that works with term.(havent tested)

    "query" : {
      "term": {
        "gender":0, "bio": "test",

default_operator:AND
}

On Sunday, 20 January 2013 12:59:13 UTC+11, ryano wrote:

I am trying to to execute a query that does 3 things:

  1. returns gender = 0;
    AND
  2. returns bio = test
    AND
  3. is within 200 mi.

Here is my query:
{
"query" : {
"term": {
"gender":0, "bio": "test"
}
},
"filter" : {
"geo_distance" : {
"distance" : "200mi",
"pos" : {
"lat" : 40,
"lon" : 40
}
}
}
}

The geographic part works fine, so that's not the problem. The problem is
the 2nd term. It basically seems to disregard the 2nd term altogether. It
does only show gender = 0, but returns all gender =0, and doesn't care what
the value of bio is. Basically, I want to do an AND query with the
gender=0 and bio="test", however I'm not clear on how to execute that. I
see the AND operator in the filters, but I don't think I want to use it as
a filter, I think I want to use it in the query.

Thanks for your assistance.

--

You need to create 2 TermQuery objects and then use those to compose a
BoolQuery...

{
"query": {
"bool": {
"must": [
{
"term": {
"gender": {
"term": "0"
}
}
},
{
"term": {
"bio": {
"term": "test"
}
}
}
]
}
}
}

Or, a simpler way would be to use a QueryStringQuery which accepts Lucene
syntax... gender:0 AND bio:test

On Saturday, January 19, 2013 8:59:13 PM UTC-5, ryano wrote:

I am trying to to execute a query that does 3 things:

  1. returns gender = 0;
    AND
  2. returns bio = test
    AND
  3. is within 200 mi.

Here is my query:
{
"query" : {
"term": {
"gender":0, "bio": "test"
}
},
"filter" : {
"geo_distance" : {
"distance" : "200mi",
"pos" : {
"lat" : 40,
"lon" : 40
}
}
}
}

The geographic part works fine, so that's not the problem. The problem is
the 2nd term. It basically seems to disregard the 2nd term altogether. It
does only show gender = 0, but returns all gender =0, and doesn't care what
the value of bio is. Basically, I want to do an AND query with the
gender=0 and bio="test", however I'm not clear on how to execute that. I
see the AND operator in the filters, but I don't think I want to use it as
a filter, I think I want to use it in the query.

Thanks for your assistance.

--