I can not just copy and paste your script to run it in Kibana dev console. As we wrote in the About the Elasticsearch category guide, could you provide something like:
DELETE index
PUT index/_doc/1
{
"foo": "bar"
}
GET index/_search
{
"query": {
"match": {
"foo": "bar"
}
}
}