# What's the performance difference between \`ids query\` and \`terms query\`?

**URL:** <https://discuss.elastic.co/t/whats-the-performance-difference-between-ids-query-and-terms-query/248398>\
**Category:** Elasticsearch\
**Created:** [September 12, 2020, 3:15am UTC](https://discuss.elastic.co/t/whats-the-performance-difference-between-ids-query-and-terms-query/248398 "2020-09-12T03:15:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morriaty](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Morriaty](https://discuss.elastic.co/u/Morriaty)\
**Post date:** [September 12, 2020, 3:15am UTC](https://discuss.elastic.co/t/whats-the-performance-difference-between-ids-query-and-terms-query/248398/1 "2020-09-12T03:15:26Z")

</div>

Say we got a large id set, then which query would be the best choice?

```python
# ids query
{
  "query": {
    "bool": {
      "filter": [
        {
          "ids" : {
            "values" : ["1", "2", ....,"100000"]
          }
        }
      ]
    }
  }
}

# terms query
{
  "query": {
    "bool": {
      "filter": [
        {
          "terms" : {
            "_id" : ["1", "2", ....,"100000"]
          }
        }
      ]
    }
  }
}

# terms lookup query
{
  "query": {
    "bool": {
      "filter": [
        {
          "terms" : {
            "_id" : {
              "index": "user",
              "type": "user",
              "id": "12345",
              "path": "followers"
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 12, 2020, 8:54am UTC](https://discuss.elastic.co/t/whats-the-performance-difference-between-ids-query-and-terms-query/248398/2 "2020-09-12T08:54:46Z")

</div>

As far as I know there is not much difference as queries with lots of terms are quite expensive and can be slow.

---

<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:** [October 10, 2020, 8:54am UTC](https://discuss.elastic.co/t/whats-the-performance-difference-between-ids-query-and-terms-query/248398/3 "2020-10-10T08:54:57Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
