# Multiple document handling

**URL:** <https://discuss.elastic.co/t/multiple-document-handling/64186>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 27, 2016, 7:08pm UTC](https://discuss.elastic.co/t/multiple-document-handling/64186 "2016-10-27T19:08:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![diopib](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diopib/32/12334_2.png) [@diopib](https://discuss.elastic.co/u/diopib)\
**Post date:** [October 27, 2016, 7:08pm UTC](https://discuss.elastic.co/t/multiple-document-handling/64186/1 "2016-10-27T19:08:47Z")

</div>

Hello,

I'm trying to use the index action, and I'm trying to save the multiple documents returned by my search.  
For that I use the transform feature and I'm attempting to return the multiple document like this:

```
"index_payload" : { 
    "transform": {
      "script" : "return [_doc : ctx.payload.hits.hits]"
      },
    
    "index" : {
      "index" : "test_index", 
      "doc_type" : "array" 
    }
  }

```

This doesn't work and I'm getting the following error:

```
{
      "id": "index_payload",
      "type": "index",
      "status": "failure",
      "reason": "NullPointerException[null]"
    }

```

Any ideas?

---

<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:** [October 28, 2016, 7:20am UTC](https://discuss.elastic.co/t/multiple-document-handling/64186/2 "2016-10-28T07:20:09Z")

</div>

Hey,

a couple of follow up question to narrow down your problem

1. What is the Elasticsearch version you are using?
2. Is there any additional output in the master node log file?
3. Does your search contain hits?
4. Can you paste the output of the [execute watch API](https://www.elastic.co/guide/en/watcher/2.4/api-rest.html#api-rest-execute-watch) here?
5. Are you sure you want to index each element of the `hits` array as own document and not the `_source` field inside of each hit?

--Alex

---

<div class="post-metadata">

**Author:** ![diopib](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diopib/32/12334_2.png) [@diopib](https://discuss.elastic.co/u/diopib)\
**Post date:** [October 28, 2016, 1:30pm UTC](https://discuss.elastic.co/t/multiple-document-handling/64186/3 "2016-10-28T13:30:52Z")

</div>

Hello,  
Thanks for your reply. Here are the details:

1. ElasticSearch version: 2.4.1 (Elastic Cloud)
2. Not sure I have access to that file...
3. Yes, the search does contain hits
4. Execute watch output:

[https://docs.google.com/a/zinaria.com/document/d/1ikhfCVazvgP\_Rru8d620zzI0OwQ-eDFH0cBvoNqWG0E/edit?usp=sharing](https://docs.google.com/a/zinaria.com/document/d/1ikhfCVazvgP_Rru8d620zzI0OwQ-eDFH0cBvoNqWG0E/edit?usp=sharing)

1. I think the \_source field of each hits would be ideal.

Thanks!

---

<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:** [October 28, 2016, 2:56pm UTC](https://discuss.elastic.co/t/multiple-document-handling/64186/4 "2016-10-28T14:56:10Z")

</div>

Hey,

I dont have access to that google doc, can you please use something, that can handle text easier, like a pastebin or a [gist](https://gist.github.com/)?

--Alex

---

<div class="post-metadata">

**Author:** ![diopib](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diopib/32/12334_2.png) [@diopib](https://discuss.elastic.co/u/diopib)\
**Post date:** [October 28, 2016, 6:07pm UTC](https://discuss.elastic.co/t/multiple-document-handling/64186/5 "2016-10-28T18:07:50Z")

</div>

Sorry, there you go:  
[https://gist.github.com/diopib/28a6ebe4837b3c15915c4dc2849787f6](https://gist.github.com/diopib/28a6ebe4837b3c15915c4dc2849787f6)  
Thanks

---

<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:** [October 31, 2016, 7:25am UTC](https://discuss.elastic.co/t/multiple-document-handling/64186/6 "2016-10-31T07:25:33Z")

</div>

Hey,

ok this does not yield anything useful either. If you are on cloud, can you please use the "Logs" console of your cluster and search for exceptions there?

Also, can you provide the full watch somewhere, so I can try to reproduce?

--Alex

---

<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:** [July 6, 2017, 1:42pm UTC](https://discuss.elastic.co/t/multiple-document-handling/64186/7 "2017-07-06T13:42:13Z")

</div>


