# Accessing search result (index\_out\_of\_bounds

**URL:** <https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [April 25, 2018, 1:59pm UTC](https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508 "2018-04-25T13:59:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickdegreef](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@rickdegreef](https://discuss.elastic.co/u/rickdegreef)\
**Post date:** [April 25, 2018, 1:59pm UTC](https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508/1 "2018-04-25T13:59:46Z")

</div>

Hi there,

When trying out the watcher, we would like to add info we collected in the input to a webhook POST request. We are trying to use the `ctx.payload.hits.hits` (with or without any index number).  
Unfortunately, every time we are getting an index\_out\_of\_bound\_exception. Our query gets over 400 hits.  
What can we do to get the information we're requesting in the body of our webhook?

---

<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:** [April 25, 2018, 2:01pm UTC](https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508/2 "2018-04-25T14:01:23Z")

</div>

the correct value would be `ctx.payload.hits.hits` - however, whenever such a kind of problem arises, the best thing would be to paste the output of the [execute watch API](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/watcher-api-execute-watch.html) in a gist.

--Alex

---

<div class="post-metadata">

**Author:** ![rickdegreef](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@rickdegreef](https://discuss.elastic.co/u/rickdegreef)\
**Post date:** [April 25, 2018, 2:20pm UTC](https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508/4 "2018-04-25T14:20:13Z")

</div>

Hi Alex,  
Thanks for your reply. This is the output we're getting:

```
    "condition": {
  "type": "compare",
  "status": "success",
  "met": true,
  "compare": {
    "resolved_values": {
      "ctx.payload.hits.total": 427
    }
  }
},
"actions": [
  {
    "id": "enterpriseAlert",
    "type": "webhook",
    "status": "failure",
    "error": {
      "root_cause": [
        {
          "type": "general_script_exception",
          "reason": "Error running com.github.mustachejava.codes.DefaultMustache@246918af"
        }
      ],
      "type": "general_script_exception",
      "reason": "Error running com.github.mustachejava.codes.DefaultMustache@246918af",
      "caused_by": {
        "type": "mustache_exception",
        "reason": "Failed to get value for ctx.payload.hits.hits.1 @[query-template:1]",
        "caused_by": {
          "type": "mustache_exception",
          "reason": "1 @[query-template:1]",
          "caused_by": {
            "type": "index_out_of_bounds_exception",
            "reason": "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:** [April 25, 2018, 2:37pm UTC](https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508/5 "2018-04-25T14:37:47Z")

</div>

please include the **full** response, this misses a lot of things. Thanks!

---

<div class="post-metadata">

**Author:** ![rickdegreef](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@rickdegreef](https://discuss.elastic.co/u/rickdegreef)\
**Post date:** [April 25, 2018, 4:06pm UTC](https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508/6 "2018-04-25T16:06:07Z")

</div>

I'm sorry. Here it is:

```
{
  "watch_id": "_inlined_",
  "node": "xAY0l29iSGKCuZOPmASWdQ",
  "state": "executed",
  "status": {
"state": {
  "active": true,
  "timestamp": "2018-04-25T16:05:03.894Z"
},
"last_checked": "2018-04-25T16:05:03.894Z",
"last_met_condition": "2018-04-25T16:05:03.894Z",
"actions": {
  "enterpriseAlert": {
    "ack": {
      "timestamp": "2018-04-25T16:05:03.894Z",
      "state": "awaits_successful_execution"
    },
    "last_execution": {
      "timestamp": "2018-04-25T16:05:03.894Z",
      "successful": false,
      "reason": ""
    }
  }
},
"execution_state": "executed",
"version": -1
  },
  "trigger_event": {
"type": "manual",
"triggered_time": "2018-04-25T16:05:03.894Z",
"manual": {
  "schedule": {
    "scheduled_time": "2018-04-25T16:05:03.894Z"
  }
}
  },
  "input": {
"search": {
  "request": {
    "search_type": "query_then_fetch",
    "indices": [
      "pymon*"
    ],
    "types": [],
    "body": {
      "size": 0,
      "query": {
        "bool": {
          "must": {
            "match": {
              "type": "Microsoft.ServiceFabric/clusters"
            }
          },
          "must_not": {
            "match": {
              "properties.clusterState": "Available"
            }
          },
          "should": [
            {
              "range": {
                "date_time": {
                  "gte": "now-5m/m"
                }
              }
            }
          ]
        }
      }
    }
  }
}
  },
  "condition": {
"compare": {
  "ctx.payload.hits.total": {
    "gte": 1
  }
}
  },
  "metadata": {
"name": "Check the status of Service Fabric",
"xpack": {
  "type": "json"
}
  },
  "result": {
"execution_time": "2018-04-25T16:05:03.894Z",
"execution_duration": 4,
"input": {
  "type": "search",
  "status": "success",
  "payload": {
    "_shards": {
      "total": 15,
      "failed": 0,
      "successful": 15,
      "skipped": 0
    },
    "hits": {
      "hits": [],
      "total": 430,
      "max_score": 0
    },
    "took": 2,
    "timed_out": false
  },
  "search": {
    "request": {
      "search_type": "query_then_fetch",
      "indices": [
        "pymon*"
      ],
      "types": [],
      "body": {
        "size": 0,
        "query": {
          "bool": {
            "must": {
              "match": {
                "type": "Microsoft.ServiceFabric/clusters"
              }
            },
            "must_not": {
              "match": {
                "properties.clusterState": "Available"
              }
            },
            "should": [
              {
                "range": {
                  "date_time": {
                    "gte": "now-5m/m"
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
},
"condition": {
  "type": "compare",
  "status": "success",
  "met": true,
  "compare": {
    "resolved_values": {
      "ctx.payload.hits.total": 430
    }
  }
},
"actions": [
  {
    "id": "enterpriseAlert",
    "type": "webhook",
    "status": "failure",
    "error": {
      "root_cause": [
        {
          "type": "general_script_exception",
          "reason": "Error running com.github.mustachejava.codes.DefaultMustache@246918af"
        }
      ],
      "type": "general_script_exception",
      "reason": "Error running com.github.mustachejava.codes.DefaultMustache@246918af",
      "caused_by": {
        "type": "mustache_exception",
        "reason": "Failed to get value for ctx.payload.hits.hits.1 @[query-template:1]",
        "caused_by": {
          "type": "mustache_exception",
          "reason": "1 @[query-template:1]",
          "caused_by": {
            "type": "index_out_of_bounds_exception",
            "reason": "1"
          }
        }
      }
    }
  }
]
  },
  "messages": []
}
```

---

<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:** [April 25, 2018, 4:44pm UTC](https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508/7 "2018-04-25T16:44:07Z")

</div>

now everything is clear. By specifying `size: 0` in your request you explicitely did not want to have the data structure in your response, you are trying to access in your action. This is why the array is emtpy.

---

<div class="post-metadata">

**Author:** ![rickdegreef](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@rickdegreef](https://discuss.elastic.co/u/rickdegreef)\
**Post date:** [April 26, 2018, 5:42am UTC](https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508/8 "2018-04-26T05:42:26Z")

</div>

Oh god. Well, that's a stupid error. Thanks for helping me solving it!  
After looking it up I found out that it isn't even a required field.

---

<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:** [May 24, 2018, 5:42am UTC](https://discuss.elastic.co/t/accessing-search-result-index-out-of-bounds/129508/9 "2018-05-24T05:42:37Z")

</div>

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