# Index action - create document

**URL:** <https://discuss.elastic.co/t/index-action-create-document/129690>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [April 26, 2018, 1:57pm UTC](https://discuss.elastic.co/t/index-action-create-document/129690 "2018-04-26T13:57:42Z")\
**Posts on this page:** 4\
**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 26, 2018, 1:57pm UTC](https://discuss.elastic.co/t/index-action-create-document/129690/1 "2018-04-26T13:57:43Z")

</div>

Hi,

We're trying to create a new document in the "action" part. We would like to index this document in the alert-index. We're trying this:

```
{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "pymon*"
        ],
        "types": [],
        "body": {
          "query": {
            "bool": {
              "must": {
                "match": {
                  "type": "microsoft.insights/components"
                }
              },
              "filter": {
                "bool": {
                  "must": [
                    {
                      "range": {
                        "date_time": {
                          "gte": "now-5m/m"
                        }
                      }
                    },
                    {
                      "range": {
                        "requests/duration": {
                          "gte": 1
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 1
      }
    }
  },
"throttle_period_in_millis": 900000,
  "actions": {
      "enterpriseAlert": {
          "webhook": {
              "scheme": "https",
              "host": "enterprisealert.arxus.eu",
              "port": 443,
              "method": "post",
              "path": "eawebservice/rest/events?apiKey=w5shm3kx0wlafe28lv6g43dh50idip3u",
              "params": {},
              "headers": {},
              "body": "title:there are {{ctx.payload.hits.total}} problems with AppInsights in Azure., type:backup/protectedItems, body:{ {{#ctx.payload.hits.hits}} client_name:{{_source.client_name}}, billing_id:{{_source.billing_id}}, object_name:{{_source.name}}, requests/duration:{{_source.requests/duration}},{{/ctx.payload.hits.hits}} }"
      }
    },
    "index_payload":{
        "index":{
            "index":"alert",
            "doc_type":"doc",
            "resource":"AppInsights",
            "total_errors":"{{ctx.payload.hits.total}}",
            "classification":"P2",
            "client_names_and_appnames":"{{#ctx.payload.hits.hits}}{{_source.client_name}} - {{_source.name}}; {{/ctx.payload.hits.hits}}",
            "date_time":"now"
        }
    }
  }
}

```

And when we're trying to simulate the action "index\_payload" we're getting the following error:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/7/071df49ef56718e2e196977040d597ca90e9905a.png)  
What are we doing wrong?

---

<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 26, 2018, 2:38pm UTC](https://discuss.elastic.co/t/index-action-create-document/129690/2 "2018-04-26T14:38:00Z")

</div>

See [https://www.elastic.co/guide/en/x-pack/6.2/actions-index.html](https://www.elastic.co/guide/en/x-pack/6.2/actions-index.html)

the index action does not allow you to configure how the document should look like. This needs to be with a transform inside of the index action like this

```auto
"index_payload" : {
  "transform" : {
    "script" : ...
  },
  "index": { ... }
}

```

the script should return a map that resembles the structure of the wanted document.

The sample watches in the [examples repository](https://github.com/elastic/examples/tree/master/Alerting) is using a fair share of actions transforms, if you need more examples.

---

<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 27, 2018, 11:40am UTC](https://discuss.elastic.co/t/index-action-create-document/129690/3 "2018-04-27T11:40:45Z")

</div>

Hi Alexander,

Thank for helping out again! This actually did the trick!

---

<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 25, 2018, 11:40am UTC](https://discuss.elastic.co/t/index-action-create-document/129690/4 "2018-05-25T11:40:51Z")

</div>

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