# Need help to create a Python script to create Index on Cluster helath API

**URL:** <https://discuss.elastic.co/t/need-help-to-create-a-python-script-to-create-index-on-cluster-helath-api/28834>\
**Category:** Elasticsearch\
**Created:** [September 8, 2015, 10:48am UTC](https://discuss.elastic.co/t/need-help-to-create-a-python-script-to-create-index-on-cluster-helath-api/28834 "2015-09-08T10:48:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas\_gopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_gopal/32/47661_2.png) [@vikas\_gopal](https://discuss.elastic.co/u/vikas_gopal)\
**Post date:** [September 8, 2015, 10:48am UTC](https://discuss.elastic.co/t/need-help-to-create-a-python-script-to-create-index-on-cluster-helath-api/28834/1 "2015-09-08T10:48:17Z")

</div>

Hi Experts ,

I am new to python , I want to create an index in ES on cluster health API . I got the following code but it's not providing me output the way I want .

import json  
import requests  
stats = requests.get('[http://localhost:9200/\_cluster/health](http://localhost:9200/_cluster/health)').json()  
abc=stats['cluster\_name']  
bulk\_data = ''  
bulk\_data += '{"index": {"\_index": "cluster", "\_type": "clust"}}\n'  
bulk\_data += json.dumps(abc) + '\n'  
response = requests.post('[http://localhost:9200/\_bulk](http://localhost:9200/_bulk)', data=bulk\_data)

Above script is able to create an index but when I am checking the data I got nothing , even in kibana when I select \_timestamp filed I got nothing . Not sure what I am doing wrong . In kibana I want to see all the fields like .

"cluster\_name": "elasticsearch",  
"status": "yellow",  
"timed\_out": false,  
"number\_of\_nodes": 1,  
"number\_of\_data\_nodes": 1,  
"active\_primary\_shards": 92,  
"active\_shards": 92,  
"relocating\_shards": 0,  
"initializing\_shards": 0,  
"unassigned\_shards": 92,  
"number\_of\_pending\_tasks": 0,  
"number\_of\_in\_flight\_fetch": 0

Please help

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 10, 2015, 8:08am UTC](https://discuss.elastic.co/t/need-help-to-create-a-python-script-to-create-index-on-cluster-helath-api/28834/2 "2015-09-10T08:08:18Z")

</div>

I tried your script but it didn't output anything to ES, in part because you need to use `_index` and `_type` in the bulk request, but then the data that was being passed into that bulk request was only the cluster name, which is not valid json.

This is what you want;

```auto
import json
import requests
stats = requests.get('http://localhost:9200/_cluster/health').json()
bulk_data = ''
bulk_data += '{"index": {"_index": "cluster", "_type": "cluster"}}\n'
bulk_data += json.dumps(stats) + '\n'
response = requests.post('http://localhost:9200/_bulk', data=bulk_data)

```

Do you mind me asking what you're doing this for?

---

<div class="post-metadata">

**Author:** ![vikas\_gopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_gopal/32/47661_2.png) [@vikas\_gopal](https://discuss.elastic.co/u/vikas_gopal)\
**Post date:** [September 10, 2015, 3:19pm UTC](https://discuss.elastic.co/t/need-help-to-create-a-python-script-to-create-index-on-cluster-helath-api/28834/3 "2015-09-10T15:19:50Z")

</div>

Script works Mark

But when I check this index in kibana I got nothing in discover tab. Can we add a current date field along with the above script so that I can select to create index on that date field, or is there any other way to do it.

---

<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 5, 2017, 11:51pm UTC](https://discuss.elastic.co/t/need-help-to-create-a-python-script-to-create-index-on-cluster-helath-api/28834/4 "2017-07-05T23:51:14Z")

</div>


