# How to Query number of Routing Shards?

**URL:** <https://discuss.elastic.co/t/how-to-query-number-of-routing-shards/214297>\
**Category:** Elasticsearch\
**Created:** [January 8, 2020, 7:53pm UTC](https://discuss.elastic.co/t/how-to-query-number-of-routing-shards/214297 "2020-01-08T19:53:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Micah\_Hunsberger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/micah_hunsberger/32/147436_2.png) [@Micah\_Hunsberger](https://discuss.elastic.co/u/Micah_Hunsberger)\
**Post date:** [January 8, 2020, 7:53pm UTC](https://discuss.elastic.co/t/how-to-query-number-of-routing-shards/214297/1 "2020-01-08T19:53:15Z")

</div>

How can I find out the number of routing shards an index was created with? I tried using the Get Index Settings API, but it doesn't show up there:

```auto
# Create the Index
PUT twitter
{
  "settings": {
    "index": {
      "number_of_shards": 5,
      "number_of_routing_shards": 20
    }
  }
}

# Get the settings
GET twitter/_settings

```

gives me this result:

```auto
{
  "twitter" : {
    "settings" : {
      "index" : {
        "creation_date" : "1578512730838",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "ZQ5h-HjdS3mFojrrpc_3GA",
        "version" : {
          "created" : "7050199"
        },
        "provided_name" : "twitter"
      }
    }
  }
}

```

which doesn't tell me the number of routing shards. I even tried querying the setting directly, but `GET twitter/_settings/index.number_of_routing_shards` just returns `{ }`

I'm using elasticearch 7.5.1

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 9, 2020, 3:38pm UTC](https://discuss.elastic.co/t/how-to-query-number-of-routing-shards/214297/2 "2020-01-09T15:38:48Z")

</div>

try using `include_defaults=true` as a parameter

---

<div class="post-metadata">

**Author:** ![Micah\_Hunsberger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/micah_hunsberger/32/147436_2.png) [@Micah\_Hunsberger](https://discuss.elastic.co/u/Micah_Hunsberger)\
**Post date:** [January 9, 2020, 4:37pm UTC](https://discuss.elastic.co/t/how-to-query-number-of-routing-shards/214297/3 "2020-01-09T16:37:42Z")

</div>

That gave me a response, but curiously it returns 1 as the answer.

```auto
GET twitter/_settings/index.number_of_routing_shards?include_defaults=true

```

```auto
{
  "twitter" : {
    "settings" : { },
    "defaults" : {
      "index" : {
        "number_of_routing_shards" : "1"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 9, 2020, 5:19pm UTC](https://discuss.elastic.co/t/how-to-query-number-of-routing-shards/214297/4 "2020-01-09T17:19:41Z")

</div>

Hm, indeed. This always seems to be "1", which is a fallback, but it should actually work with a multipler of the number of shards. Let me check that tomorrow and come back to you.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 10, 2020, 2:13pm UTC](https://discuss.elastic.co/t/how-to-query-number-of-routing-shards/214297/5 "2020-01-10T14:13:44Z")

</div>

I found [https://github.com/elastic/elasticsearch/issues/33036](https://github.com/elastic/elasticsearch/issues/33036) telling that the setting is not exposed in the index settings. The issue however is still open.

---

<div class="post-metadata">

**Author:** ![Micah\_Hunsberger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/micah_hunsberger/32/147436_2.png) [@Micah\_Hunsberger](https://discuss.elastic.co/u/Micah_Hunsberger)\
**Post date:** [January 10, 2020, 2:40pm UTC](https://discuss.elastic.co/t/how-to-query-number-of-routing-shards/214297/6 "2020-01-10T14:40:13Z")

</div>

Fair enough, thanks @spinscale!

Looks like a possible workaround mentioned in that issue is to call the \_split API with an invalid number of target shards, and the error response will include the number of routing shards.  
So in this example you could try

```auto
POST twitter/_split/target-index
{
  "settings": {
    "index.number_of_shards": 15
  }
}

```

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_state_exception",
        "reason": "the number of routing shards [20] must be a multiple of the target shards [15]"
      }
    ],
    "type": "illegal_state_exception",
    "reason": "the number of routing shards [20] must be a multiple of the target shards [15]"
  },
  "status": 500
}

```

The problem is you could potentially pick a valid number and split the index. To be safer, you could try setting `index.number_of_shards` to a very high number, making it unlikely that the number of routing shards is a multiple. Probably a better solution is to just use templates and trust the setting in the template is correct.

---

<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:** [February 7, 2020, 2:40pm UTC](https://discuss.elastic.co/t/how-to-query-number-of-routing-shards/214297/7 "2020-02-07T14:40:17Z")

</div>

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