# Multiple query terms

**URL:** <https://discuss.elastic.co/t/multiple-query-terms/10424>\
**Category:** Elasticsearch\
**Created:** [January 20, 2013, 1:59am UTC](https://discuss.elastic.co/t/multiple-query-terms/10424 "2013-01-20T01:59:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanogle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ryanogle/32/2404_2.png) [@ryanogle](https://discuss.elastic.co/u/ryanogle)\
**Post date:** [January 20, 2013, 1:59am UTC](https://discuss.elastic.co/t/multiple-query-terms/10424/1 "2013-01-20T01:59:13Z")

</div>

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.

--

---

<div class="post-metadata">

**Author:** ![moocow](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/moocow/32/2454_2.png) [@moocow](https://discuss.elastic.co/u/moocow)\
**Post date:** [January 20, 2013, 2:28am UTC](https://discuss.elastic.co/t/multiple-query-terms/10424/2 "2013-01-20T02:28:39Z")

</div>

hi ryano

not sure if this will help but I used query\_string instead of term

curl -XGET '[http://localhost:9200/lists/list/\_search](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.

--

---

<div class="post-metadata">

**Author:** ![egaumer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/egaumer/32/2365_2.png) [@egaumer](https://discuss.elastic.co/u/egaumer)\
**Post date:** [January 20, 2013, 3:36am UTC](https://discuss.elastic.co/t/multiple-query-terms/10424/3 "2013-01-20T03:36:46Z")

</div>

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.

--

---

<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:55am UTC](https://discuss.elastic.co/t/multiple-query-terms/10424/4 "2017-07-06T02:55:30Z")

</div>

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


