# Ids Query is slow in 2b docs

**URL:** <https://discuss.elastic.co/t/ids-query-is-slow-in-2b-docs/145032>\
**Category:** Elasticsearch\
**Created:** [August 19, 2018, 3:52am UTC](https://discuss.elastic.co/t/ids-query-is-slow-in-2b-docs/145032 "2018-08-19T03:52:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chzyer](https://avatars.discourse-cdn.com/v4/letter/c/779978/32.png) [@chzyer](https://discuss.elastic.co/u/chzyer)\
**Post date:** [August 19, 2018, 3:52am UTC](https://discuss.elastic.co/t/ids-query-is-slow-in-2b-docs/145032/1 "2018-08-19T03:52:03Z")

</div>

Version: 6.2.4  
Documents: 1979484267  
Shards: 30 in 30 hosts  
Document sample:

```auto
{
          "goods_id": 2466330584,
          "cate_id": 6247,
          "property_value_ids": []
}

```

What we want to do is query specified docs with \_id(same as goods\_id). which like

```auto
{
  "_source": ["_id"],
  "profile": false,
  "query": {
    "bool": {
      "filter": [
        {
          "ids": {
            "type": "goods",
            "values": [
              2035275709,
              ... 
            ]
          }
        }
      ]
    }
  }

```

It's quite simple. It's about 1,000 ids per search request.

**But it takes about 20ms!! If I decrease the ids size to 5, it takes ~5ms**

So I try to profile them, it seems send all 1,000 ids to all shards without calculating where we belongs to, like sending [1, 3, 5] to shard 1, and [2, 4, 6] to shard 2.

Any idea to speed up this?  
Thanks!

---

<div class="post-metadata">

**Author:** ![ddorian43](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ddorian43/32/36093_2.png) [@ddorian43](https://discuss.elastic.co/u/ddorian43)\
**Post date:** [August 19, 2018, 8:10am UTC](https://discuss.elastic.co/t/ids-query-is-slow-in-2b-docs/145032/2 "2018-08-19T08:10:09Z")

</div>

1. Can you remove types ? by using latest es version and not using types. this will store \_id as binary, using nearly ~8 bytes. This will make \_id smaller/shorter and faster to query.
2. This takes time. You have to keep on the client-side a map of `{shard_id: node}`. And when you do a query, you calculate the shard of each `_id`, you group by \_node and then you do 30 single queries directly on the node.

---

<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:** [September 16, 2018, 8:10am UTC](https://discuss.elastic.co/t/ids-query-is-slow-in-2b-docs/145032/3 "2018-09-16T08:10:11Z")

</div>

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