# How to do Bulk API iteration from JSON lines using Python?

**URL:** <https://discuss.elastic.co/t/how-to-do-bulk-api-iteration-from-json-lines-using-python/314218>\
**Category:** Elasticsearch\
**Created:** [September 12, 2022, 6:11pm UTC](https://discuss.elastic.co/t/how-to-do-bulk-api-iteration-from-json-lines-using-python/314218 "2022-09-12T18:11:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramu\_Kakaji](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramu_kakaji/32/102811_2.png) [@Ramu\_Kakaji](https://discuss.elastic.co/u/Ramu_Kakaji)\
**Post date:** [September 12, 2022, 6:11pm UTC](https://discuss.elastic.co/t/how-to-do-bulk-api-iteration-from-json-lines-using-python/314218/1 "2022-09-12T18:11:33Z")

</div>

Hi All,

i have json data like this

json\_data =

```auto
{ "title": "Rush", "year": 2013, "budget":500000, "earning":300000,"genere":"action"}
{ "title": "Jurrasic", "year": 2014,"budget":1500000, "earning":2300000,"genere":"action"}
{ "title": "Dr Strange", "year": 2022,"budget":2500000, "earning":5000000,"genere":"Sci-fi"}
{ "title": "Avatar", "year": 2009,"budget":1200000, "earning":6000000,"genere":"Sci-fi"}

```

in reality it should become like this

```auto
{ "index": { "_index": "index_name", "_id": "tt1979320" } }
{ "title": "Rush", "year": 2013, "budget":500000, "earning":300000,"genere":"action"}
{ "index": { "_index": "index_name", "_id": "tt1979321" } }
{ "title": "Jurrasic", "year": 2014,"budget":1500000, "earning":2300000,"genere":"action"}
{ "index": { "_index": "index_name", "_id": "tt1979322" } }
{ "title": "Dr Strange", "year": 2022,"budget":2500000, "earning":5000000,"genere":"Sci-fi"}
{ "index": { "_index": "index_name", "_id": "tt1979323" } }
{ "title": "Avatar", "year": 2009,"budget":1200000, "earning":6000000,"genere":"Sci-fi"}

```

I need to do bulk load using python client

I need help in writing the action to do bulk indexing

```auto
actions = [
  {
    "_op_type": 'index'
    "_index": index_name,
    "_id": # should come from json_data,
    "_source": {
        "any":"data" # should come from json_data
  }
  for count in range(0, 10) # this is just to get batch of 10 but not sure what is the right way
]

```

print(actions)  
response = bulk(client,actions)  
print(response)

---

<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:** [October 10, 2022, 6:12pm UTC](https://discuss.elastic.co/t/how-to-do-bulk-api-iteration-from-json-lines-using-python/314218/2 "2022-10-10T18:12:03Z")

</div>

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