# Elastic bulk API Multiple docs with single action

**URL:** <https://discuss.elastic.co/t/elastic-bulk-api-multiple-docs-with-single-action/75882>\
**Category:** Elasticsearch\
**Created:** [February 21, 2017, 1:09pm UTC](https://discuss.elastic.co/t/elastic-bulk-api-multiple-docs-with-single-action/75882 "2017-02-21T13:09:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsb](https://avatars.discourse-cdn.com/v4/letter/g/cc9497/32.png) [@gsb](https://discuss.elastic.co/u/gsb)\
**Post date:** [February 21, 2017, 1:09pm UTC](https://discuss.elastic.co/t/elastic-bulk-api-multiple-docs-with-single-action/75882/1 "2017-02-21T13:09:45Z")

</div>

I'm trying to index multiple docs on a single action (index), is there any way to avoid repeating the action with each document in the input.

curl -XPOST '[https://localhost:9200/myindex/mytype/\_bulk?pretty](https://localhost:9200/myindex/mytype/_bulk?pretty)' -H 'Content-Type: application/json' -d'  
{"index" : {}}  
{ "field1" : "value1","field2": "value2"}  
{"index" : {}}  
{ "field1" : "value12","field2": "value22"}  
'  
In this case , is there any way to avoid repeating {"index" : {}} before each document ?

---

<div class="post-metadata">

**Author:** ![jkuang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jkuang/32/72637_2.png) [@jkuang](https://discuss.elastic.co/u/jkuang)\
**Post date:** [February 21, 2017, 6:29pm UTC](https://discuss.elastic.co/t/elastic-bulk-api-multiple-docs-with-single-action/75882/2 "2017-02-21T18:29:41Z")

</div>

I do not see a way to avoid repeating the {"index" : {}} before each document, but I made it easier to do so by using the find and replace on my notepad.

For example: Mytest.txt

{ "field1" : "value1","field2": "value2"}  
{ "field1" : "value12","field2": "value22"}  
.....  
....

Find { "field1" :  
Replace {"index" : {}}  
{ "field1" :

Now in my Mytest.txt I see

{"index" : {}}  
{ "field1" : "value1","field2": "value2"}  
{"index" : {}}  
{ "field1" : "value12","field2": "value22"}  
.....  
.....

curl -k -XPOST '[https://localhost:9200/myindex/mytype/\_bulk?pretty](https://localhost:9200/myindex/mytype/_bulk?pretty)' --data-binary "@Mytest.txt" -H 'Content-Type: application/json'

---

<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:** [March 21, 2017, 6:30pm UTC](https://discuss.elastic.co/t/elastic-bulk-api-multiple-docs-with-single-action/75882/3 "2017-03-21T18:30:06Z")

</div>

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