# RE: creating an index using Python?

**URL:** <https://discuss.elastic.co/t/re-creating-an-index-using-python/10688>\
**Category:** Elasticsearch\
**Created:** [February 10, 2013, 3:19pm UTC](https://discuss.elastic.co/t/re-creating-an-index-using-python/10688 "2013-02-10T15:19:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elastic\_Noob](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@Elastic\_Noob](https://discuss.elastic.co/u/Elastic_Noob)\
**Post date:** [February 10, 2013, 3:19pm UTC](https://discuss.elastic.co/t/re-creating-an-index-using-python/10688/1 "2013-02-10T15:19:47Z")

</div>

Hi good day,

I have a question regarding creating an ElasticSearch index using Python  
Requests Library ( [http://docs.python-requests.org/en/latest/](http://docs.python-requests.org/en/latest/) )

I'm not too sure if the issue I am having is with ElasticSearch or with  
Python Requests library....

Background:  
I'm using Requests for perform cURL requests to a ElasticSearch endpoint (  
[http://www.elasticsearch](http://www.elasticsearch)  
.org/guide/reference/api/admin-indices-create-index.html )

In particular, I am trying to create an index setting.

This code works:  
( on command line )

eugene$: curl -XPUT '[http://localhost:9200/testindex4](http://localhost:9200/testindex4)' -d '{"settings": {  
"index" : { "number\_of\_shards":3,"number\_of\_replicas":2}}}'

The above creates the expected settings.

However, doing the same thing using Requests does not work:

test\_settings = {'settings': {'index': {'number\_of\_replicas': 2,  
'number\_of\_shards': 3}}}

# create an index with test\_settings:

index\_test = requests.put('[http://localhost:9200/testindex](http://localhost:9200/testindex)',  
data=test\_settings) # this line is successful

# get the settings of index\_test

check\_settings = requests.get('[http://localhost:9200/testindex/\_settings](http://localhost:9200/testindex/_settings)')  
print check\_settings.json()

# returns the following:

{u'index\_test': {u'settings': {u'index.version.created': u'200299',  
u'index.number\_of\_shards': u'5', u'index.number\_of\_replicas': u'1',  
u'index.settings': u'index'}}}

Notice that the index.number\_of\_replicas is not 2, and  
index.number\_of\_shards is not 3.

I was wondering if there's a bug with Requests? Or is it a problem with  
elasticsearch ?

Is there any way I can create an index via the Python Request Library ? (  
or perhaps cURL library? )

Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![egaumer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/egaumer/32/2365_2.png) [@egaumer](https://discuss.elastic.co/u/egaumer)\
**Post date:** [February 10, 2013, 3:36pm UTC](https://discuss.elastic.co/t/re-creating-an-index-using-python/10688/2 "2013-02-10T15:36:56Z")

</div>

You need to send the a json string...

index\_test = requests.put('[http://localhost:9200/testindex](http://localhost:9200/testindex)',  
data=json.dumps(test\_settings))

On Sunday, February 10, 2013 10:19:47 AM UTC-5, Elastic Noob wrote:

> Hi good day,
> 
> I have a question regarding creating an Elasticsearch index using Python  
> Requests Library ( [Requests: HTTP for Humans™ — Requests 2.31.0 documentation](http://docs.python-requests.org/en/latest/) )
> 
> I'm not too sure if the issue I am having is with Elasticsearch or with  
> Python Requests library....
> 
> Background:  
> I'm using Requests for perform cURL requests to a Elasticsearch endpoint  
> ( [http://www.elasticsearch](http://www.elasticsearch)  
> .org/guide/reference/api/admin-indices-create-index.html )
> 
> In particular, I am trying to create an index setting.
> 
> This code works:  
> ( on command line )
> 
> eugene$: curl -XPUT '[http://localhost:9200/testindex4](http://localhost:9200/testindex4)' -d '{"settings": {  
> "index" : { "number\_of\_shards":3,"number\_of\_replicas":2}}}'
> 
> The above creates the expected settings.
> 
> However, doing the same thing using Requests does not work:
> 
> test\_settings = {'settings': {'index': {'number\_of\_replicas': 2,  
> 'number\_of\_shards': 3}}}
> 
> # create an index with test\_settings:
> 
> index\_test = requests.put('[http://localhost:9200/testindex](http://localhost:9200/testindex)',  
> data=test\_settings) # this line is successful
> 
> # get the settings of index\_test
> 
> check\_settings = requests.get('[http://localhost:9200/testindex/\_settings](http://localhost:9200/testindex/_settings)')  
> print check\_settings.json()
> 
> # returns the following:
> 
> {u'index\_test': {u'settings': {u'index.version.created': u'200299',  
> u'index.number\_of\_shards': u'5', u'index.number\_of\_replicas': u'1',  
> u'index.settings': u'index'}}}
> 
> Notice that the index.number\_of\_replicas is not 2, and  
> index.number\_of\_shards is not 3.
> 
> I was wondering if there's a bug with Requests? Or is it a problem with  
> elasticsearch ?
> 
> Is there any way I can create an index via the Python Request Library ? (  
> or perhaps cURL library? )
> 
> Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Kenneth\_Loafman\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kenneth_loafman_2/32/2224_2.png) [@Kenneth\_Loafman\_2](https://discuss.elastic.co/u/Kenneth_Loafman_2)\
**Post date:** [February 11, 2013, 1:49pm UTC](https://discuss.elastic.co/t/re-creating-an-index-using-python/10688/3 "2013-02-11T13:49:14Z")

</div>

There is a very good Python package for Elasticsearch called pyes:

> **[GitHub - aparo/pyes: Python connector for ElasticSearch - the pythonic way to...](https://github.com/aparo/pyes)**
>
> Python connector for ElasticSearch - the pythonic way to use ElasticSearch - GitHub - aparo/pyes: Python connector for ElasticSearch - the pythonic way to use ElasticSearch

...Ken

On Sun, Feb 10, 2013 at 9:36 AM, egaumer [egaumer@gmail.com](mailto:egaumer@gmail.com) wrote:

> You need to send the a json string...
> 
> index\_test = requests.put('[http://localhost:9200/testindex](http://localhost:9200/testindex)',  
> data=json.dumps(test\_settings))
> 
> On Sunday, February 10, 2013 10:19:47 AM UTC-5, Elastic Noob wrote:
> 
> > Hi good day,
> > 
> > I have a question regarding creating an Elasticsearch index using Python  
> > Requests Library ( [Requests: HTTP for Humans™ — Requests 2.31.0 documentation](http://docs.python-requests.org/en/latest/) )
> > 
> > I'm not too sure if the issue I am having is with Elasticsearch or with  
> > Python Requests library....
> > 
> > Background:  
> > I'm using Requests for perform cURL requests to a Elasticsearch endpoint (  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html)  
> > )
> > 
> > In particular, I am trying to create an index setting.
> > 
> > This code works:  
> > ( on command line )
> > 
> > eugene$: curl -XPUT '[http://localhost:9200/testindex4](http://localhost:9200/testindex4)' -d '{"settings": {  
> > "index" : { "number\_of\_shards":3,"number\_of\_replicas":2}}}'
> > 
> > The above creates the expected settings.
> > 
> > However, doing the same thing using Requests does not work:
> > 
> > test\_settings = {'settings': {'index': {'number\_of\_replicas': 2,  
> > 'number\_of\_shards': 3}}}
> > 
> > # create an index with test\_settings:
> > 
> > index\_test = requests.put('[http://localhost:9200/testindex](http://localhost:9200/testindex)',  
> > data=test\_settings) # this line is successful
> > 
> > # get the settings of index\_test
> > 
> > check\_settings = requests.get('[http://localhost:9200/testindex/\_settings](http://localhost:9200/testindex/_settings)')  
> > print check\_settings.json()
> > 
> > # returns the following:
> > 
> > {u'index\_test': {u'settings': {u'index.version.created': u'200299',  
> > u'index.number\_of\_shards': u'5', u'index.number\_of\_replicas': u'1',  
> > u'index.settings': u'index'}}}
> > 
> > Notice that the index.number\_of\_replicas is not 2, and  
> > index.number\_of\_shards is not 3.
> > 
> > I was wondering if there's a bug with Requests? Or is it a problem with  
> > elasticsearch ?
> > 
> > Is there any way I can create an index via the Python Request Library ? (  
> > or perhaps cURL library? )
> > 
> > Thanks!
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Elastic\_Noob](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@Elastic\_Noob](https://discuss.elastic.co/u/Elastic_Noob)\
**Post date:** [February 12, 2013, 9:49am UTC](https://discuss.elastic.co/t/re-creating-an-index-using-python/10688/4 "2013-02-12T09:49:11Z")

</div>

Hi, thanks for the reply!

The library don't seem to be updated recently.

Is there any other libraries? Or is the library in question working alright  
in your experience ?

Best .

On Monday, February 11, 2013 9:49:14 PM UTC+8, Kenneth Loafman wrote:

> There is a very good Python package for Elasticsearch called pyes:  
> [GitHub - aparo/pyes: Python connector for ElasticSearch - the pythonic way to use ElasticSearch](https://github.com/aparo/pyes)
> 
> ...Ken
> 
> On Sun, Feb 10, 2013 at 9:36 AM, egaumer \<[ega...@gmail.com](mailto:ega...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > You need to send the a json string...
> > 
> > index\_test = requests.put('[http://localhost:9200/testindex](http://localhost:9200/testindex)',  
> > data=json.dumps(test\_settings))
> > 
> > On Sunday, February 10, 2013 10:19:47 AM UTC-5, Elastic Noob wrote:
> > 
> > > Hi good day,
> > > 
> > > I have a question regarding creating an Elasticsearch index using  
> > > Python  
> > > Requests Library ( [Requests: HTTP for Humans™ — Requests 2.31.0 documentation](http://docs.python-requests.org/en/latest/) )
> > > 
> > > I'm not too sure if the issue I am having is with Elasticsearch or with  
> > > Python Requests library....
> > > 
> > > Background:  
> > > I'm using Requests for perform cURL requests to a Elasticsearch  
> > > endpoint (
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html)
> 
> > > )
> > > 
> > > In particular, I am trying to create an index setting.
> > > 
> > > This code works:  
> > > ( on command line )
> > > 
> > > eugene$: curl -XPUT '[http://localhost:9200/testindex4](http://localhost:9200/testindex4)' -d  
> > > '{"settings": {  
> > > "index" : { "number\_of\_shards":3,"number\_of\_replicas":2}}}'
> > > 
> > > The above creates the expected settings.
> > > 
> > > However, doing the same thing using Requests does not work:
> > > 
> > > test\_settings = {'settings': {'index': {'number\_of\_replicas': 2,  
> > > 'number\_of\_shards': 3}}}
> > > 
> > > # create an index with test\_settings:
> > > 
> > > index\_test = requests.put('[http://localhost:9200/testindex](http://localhost:9200/testindex)',  
> > > data=test\_settings) # this line is successful
> > > 
> > > # get the settings of index\_test
> > > 
> > > check\_settings = requests.get('  
> > > [http://localhost:9200/testindex/\_settings](http://localhost:9200/testindex/_settings)')  
> > > print check\_settings.json()
> > > 
> > > # returns the following:
> > > 
> > > {u'index\_test': {u'settings': {u'index.version.created': u'200299',  
> > > u'index.number\_of\_shards': u'5', u'index.number\_of\_replicas': u'1',  
> > > u'index.settings': u'index'}}}
> > > 
> > > Notice that the index.number\_of\_replicas is not 2, and  
> > > index.number\_of\_shards is not 3.
> > > 
> > > I was wondering if there's a bug with Requests? Or is it a problem with  
> > > elasticsearch ?
> > > 
> > > Is there any way I can create an index via the Python Request Library ?  
> > > (  
> > > or perhaps cURL library? )
> > > 
> > > Thanks!
> > 
> > --  
> > You received this message because you are subscribed to the Google  
> > Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send  
> > an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Elastic\_Noob](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@Elastic\_Noob](https://discuss.elastic.co/u/Elastic_Noob)\
**Post date:** [February 12, 2013, 9:49am UTC](https://discuss.elastic.co/t/re-creating-an-index-using-python/10688/5 "2013-02-12T09:49:24Z")

</div>

Got it!

Thanks!

On Sunday, February 10, 2013 11:36:56 PM UTC+8, egaumer wrote:

> You need to send the a json string...
> 
> index\_test = requests.put('[http://localhost:9200/testindex](http://localhost:9200/testindex)',  
> data=json.dumps(test\_settings))
> 
> On Sunday, February 10, 2013 10:19:47 AM UTC-5, Elastic Noob wrote:
> 
> > Hi good day,
> > 
> > I have a question regarding creating an Elasticsearch index using Python  
> > Requests Library ( [Requests: HTTP for Humans™ — Requests 2.31.0 documentation](http://docs.python-requests.org/en/latest/) )
> > 
> > I'm not too sure if the issue I am having is with Elasticsearch or with  
> > Python Requests library....
> > 
> > Background:  
> > I'm using Requests for perform cURL requests to a Elasticsearch endpoint  
> > ( [http://www.elasticsearch](http://www.elasticsearch)  
> > .org/guide/reference/api/admin-indices-create-index.html )
> > 
> > In particular, I am trying to create an index setting.
> > 
> > This code works:  
> > ( on command line )
> > 
> > eugene$: curl -XPUT '[http://localhost:9200/testindex4](http://localhost:9200/testindex4)' -d '{"settings":  
> > { "index" : { "number\_of\_shards":3,"number\_of\_replicas":2}}}'
> > 
> > The above creates the expected settings.
> > 
> > However, doing the same thing using Requests does not work:
> > 
> > test\_settings = {'settings': {'index': {'number\_of\_replicas': 2,  
> > 'number\_of\_shards': 3}}}
> > 
> > # create an index with test\_settings:
> > 
> > index\_test = requests.put('[http://localhost:9200/testindex](http://localhost:9200/testindex)',  
> > data=test\_settings) # this line is successful
> > 
> > # get the settings of index\_test
> > 
> > check\_settings = requests.get('[http://localhost:9200/testindex/\_settings](http://localhost:9200/testindex/_settings)  
> > ')  
> > print check\_settings.json()
> > 
> > # returns the following:
> > 
> > {u'index\_test': {u'settings': {u'index.version.created': u'200299',  
> > u'index.number\_of\_shards': u'5', u'index.number\_of\_replicas': u'1',  
> > u'index.settings': u'index'}}}
> > 
> > Notice that the index.number\_of\_replicas is not 2, and  
> > index.number\_of\_shards is not 3.
> > 
> > I was wondering if there's a bug with Requests? Or is it a problem with  
> > elasticsearch ?
> > 
> > Is there any way I can create an index via the Python Request Library ? (  
> > or perhaps cURL library? )
> > 
> > Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:51am UTC](https://discuss.elastic.co/t/re-creating-an-index-using-python/10688/6 "2017-07-06T02:51:55Z")

</div>


