# How to recreate shard failure

**URL:** <https://discuss.elastic.co/t/how-to-recreate-shard-failure/310114>\
**Category:** Elasticsearch\
**Created:** [July 20, 2022, 8:33am UTC](https://discuss.elastic.co/t/how-to-recreate-shard-failure/310114 "2022-07-20T08:33:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vel/32/77829_2.png) [@vel](https://discuss.elastic.co/u/vel)\
**Post date:** [July 20, 2022, 8:33am UTC](https://discuss.elastic.co/t/how-to-recreate-shard-failure/310114/1 "2022-07-20T08:33:10Z")

</div>

I am trying to find a way for recreating the shard failure in Elasticsearch  
When querying ES can return a 200 response , even if one of the shards had failed to respond.  
how do I recreate error, for testing.

```auto

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 1,
    "failures" : [
      {
        "shard" : 1,
        "index" : "hidden_2022-07-19_07_47_32.907435",
        "node" : "J63Vl4b4SC-YrxTFENgijA",
        "reason" : {
          "type" : "node_not_connected_exception",
          "reason" : "[elasticsearch3][172.19.0.2:9300] Node not connected"
        }
      }
    ]
  },
  "hits" : {
    "total" : {
      "value" : 26,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

---

<div class="post-metadata">

**Author:** ![EricDavisX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ericdavisx/32/73456_2.png) [@EricDavisX](https://discuss.elastic.co/u/EricDavisX)\
**Post date:** [July 20, 2022, 4:37pm UTC](https://discuss.elastic.co/t/how-to-recreate-shard-failure/310114/2 "2022-07-20T16:37:05Z")

</div>

HI, thanks for asking. For now, I have removed the elastic-stack-alerting label as I don't follow how it relates. I could guess you are doing this testing in the context of some alerts usage? It may help later, but the core question seems unrelated so I'm not deep enough into Elasticsearch to be able to help.

We can ask another team for help on this if you can offer more content - and someone will write back either way, I expect. Let us know. Cheers.

---

<div class="post-metadata">

**Author:** ![Julie\_Tibshirani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julie_tibshirani/32/55628_2.png) [@Julie\_Tibshirani](https://discuss.elastic.co/u/Julie_Tibshirani)\
**Post date:** [July 21, 2022, 3:52am UTC](https://discuss.elastic.co/t/how-to-recreate-shard-failure/310114/3 "2022-07-21T03:52:47Z")

</div>

Hello, I'm on the Elasticsearch team and may be able to help.

To check, are you trying to simulate the situation in automated tests where only a few shards fail (so you get a partial response)? One option is to create two indices containing some field "field", one with the "field" mapped as "integer", and the other as "keyword". Then you could search across both indices using a "range" query on some non-numeric value -- it will fail on the index shards where the field is mapped as "integer" with a parsing exception.

Here is the general idea:

```auto
PUT index
{
  "mappings": {
    "properties": {
      "field": { "type": "integer" }
    }
  }
}

PUT index2
{
  "mappings": {
    "properties": {
      "field": { "type": "keyword" }
    }
  }
}

POST index,index2/_search
{
  "query": {
    "range": {
      "field": {
        "gt": "julie"
      }
    }
  }
}

```

For our internal testing, we developed a module with a special "error-query" to simulate shard failures and warnings ([Add a test module to simulate errors and warnings in search requests by jimczi · Pull Request #71674 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/pull/71674)). This is a test module and is only exposed in the daily Elasticsearch snapshot builds.

---

<div class="post-metadata">

**Author:** ![vel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vel/32/77829_2.png) [@vel](https://discuss.elastic.co/u/vel)\
**Post date:** [July 22, 2022, 6:03am UTC](https://discuss.elastic.co/t/how-to-recreate-shard-failure/310114/4 "2022-07-22T06:03:50Z")

</div>

Thanks for taking time to answer.

---

<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:** [August 19, 2022, 6:04am UTC](https://discuss.elastic.co/t/how-to-recreate-shard-failure/310114/5 "2022-08-19T06:04:49Z")

</div>

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