---
"Response format for search failures":
  - do:
      indices.create:
        index: source
        body:
          settings:
            index.number_of_shards: 2

  - do:
      index:
        index:   source
        id:      "1"
        body:    { "text": "test" }
  - do:
      indices.refresh: {}

  - do:
      catch: bad_request
      update_by_query:
        index:   source
        body:
          query:
            script:
              script:
                lang: painless
                source: throw new IllegalArgumentException("Cats!")
  - match: {error.type: search_phase_execution_exception}
  - match: {error.reason: "Partial shards failure"}
  - match: {error.phase: query}
  - match: {error.root_cause.0.type:   script_exception}
  - match: {error.root_cause.0.reason: runtime error}
  # The shard number can vary based on the shard routing function version. Just check that it's between 0 and 1.
  - gte: { error.failed_shards.0.shard: 0 }
  - lte: { error.failed_shards.0.shard: 1 }
  - match: {error.failed_shards.0.index:  source}
  - is_true: error.failed_shards.0.node
  - match: {error.failed_shards.0.reason.type:   script_exception}
  - match: {error.failed_shards.0.reason.reason: runtime error}
  - match: {error.failed_shards.0.reason.caused_by.type:   illegal_argument_exception}
  - match: {error.failed_shards.0.reason.caused_by.reason: Cats!}
