# Search by ids and term both

**URL:** https://discuss.elastic.co/t/search-by-ids-and-term-both/50932
**Category:** Elasticsearch
**Created:** [May 25, 2016, 11:54am UTC](https://discuss.elastic.co/t/search-by-ids-and-term-both/50932 "2016-05-25T11:54:49Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![enp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enp/32/3825_2.png) [@enp](https://discuss.elastic.co/u/enp)
#### Post date: [May 25, 2016, 11:54am UTC](https://discuss.elastic.co/t/search-by-ids-and-term-both/50932/1 "2016-05-25T11:54:49Z")

</div>

Hi,

Is it possible to search by ids and term both? I tried to do something like:

`curl -XGET 'http://localhost:9200/hotels/hotel/_search' -d ' { "query" : { "ids" : { "values" : ["c900640a-12e5-4f02-8fec-07f6f4bf58ab", "56d46e68-07e8-4502-be08-df68730bae67"] }, "term" : { "type" : "couple" } } } '`  
but result was:

`# ERROR: Search::Elasticsearch::Error::Request [http://localhost:9200]-[400] [parse_exception] failed to parse search source. expected field name but got [START_OBJECT]`

Query by ids or term only works fine

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [May 26, 2016, 12:10am UTC](https://discuss.elastic.co/t/search-by-ids-and-term-both/50932/2 "2016-05-26T00:10:20Z")

</div>

Are you essentially stating these should be an OR, or are you doing some filtering?

---

<div class="post-metadata">

### Author: ![NgocPham](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ngocpham/32/6242_2.png) [@NgocPham](https://discuss.elastic.co/u/NgocPham)
#### Post date: [May 26, 2016, 4:13am UTC](https://discuss.elastic.co/t/search-by-ids-and-term-both/50932/3 "2016-05-26T04:13:12Z")

</div>

i try with java and it work together.  
here is code i tried

```
 SearchResponse response =
            this.client
                .prepareSearch("hotels")
                .setQuery(
                   QueryBuilders.boolQuery().should(QueryBuilders.idsQuery("c900640a-12e5-4f02-8fec-07f6f4bf58ab"))
                        .should(QueryBuilders.termQuery("type", "couple"))).setSize(10000).execute().actionGet();

```

Im not sure how to code by CURL, i will try and comment if i find it later

Here is code it auto convert from java to query curl, but i think have something wrong :))

```
{
  "bool" : {
    "should" : [ {
      "ids" : {
        "type" : "c900640a-12e5-4f02-8fec-07f6f4bf58ab",
        "values" : []
      }
    }, {
      "term" : {
        "type" : "couple"
      }
    } ]
  }
}
```

---

<div class="post-metadata">

### Author: ![enp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enp/32/3825_2.png) [@enp](https://discuss.elastic.co/u/enp)
#### Post date: [May 26, 2016, 4:48am UTC](https://discuss.elastic.co/t/search-by-ids-and-term-both/50932/4 "2016-05-26T04:48:44Z")

</div>

> [@warkolm](#):
>
> Are you essentially stating these should be an OR, or are you doing some filtering?

I need to filter by ids AND term

---

<div class="post-metadata">

### Author: ![enp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enp/32/3825_2.png) [@enp](https://discuss.elastic.co/u/enp)
#### Post date: [May 26, 2016, 4:54am UTC](https://discuss.elastic.co/t/search-by-ids-and-term-both/50932/5 "2016-05-26T04:54:34Z")

</div>

> [@NgocPham](#):
>
> i try with java and it work together.

It looks like second 'should' call rewrites first 'should' call. I tried to do the same in perl clent, but with:

`query => { bool => { should => { ids => { values => $ids }}, should => { term => { "type" => "couple" }}}}`

I got:

```
"query" : {
      "bool" : {
         "should" : {
            "term" : {
               "type" : "couple"
            }
         }
      }
   }

```

---

<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 5, 2017, 10:48pm UTC](https://discuss.elastic.co/t/search-by-ids-and-term-both/50932/6 "2017-07-05T22:48:57Z")

</div>


