# Elasticsearch-py index and get errors

**URL:** <https://discuss.elastic.co/t/elasticsearch-py-index-and-get-errors/34124>\
**Category:** Elasticsearch\
**Created:** [November 9, 2015, 5:51am UTC](https://discuss.elastic.co/t/elasticsearch-py-index-and-get-errors/34124 "2015-11-09T05:51:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pstarrett1](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@pstarrett1](https://discuss.elastic.co/u/pstarrett1)\
**Post date:** [November 9, 2015, 5:51am UTC](https://discuss.elastic.co/t/elasticsearch-py-index-and-get-errors/34124/1 "2015-11-09T05:51:27Z")

</div>

Below code creates traceback that follows. I am trying to get json file into and out of ES and have checked documentation but cannot seem to resolve. Appreciate any help!

Code:

d = {}  
def text\_to\_json(data):  
for k,v in data.items():  
with open(v, 'r') as r:  
cont = r.read().strip()  
d[k] = cont

```
a = json.dumps(d)
return a

```

engine\_and\_file = {  
'Google': './page\_content\_first.txt/part-00000',  
}

a = (text\_to\_json(engine\_and\_file))

es.index('webpage-import', 'html', a)  
es.get('webpage-import', 'html', id=1)

Traceback (most recent call last):  
File "/home/ubuntu/Python\_Projects/Spark/spark-1.5.1-bin-hadoop2.6/./Spark\_FileImport\_Test.py", line 60, in   
es.get('webpage-import', 'html', id=1)  
File "/usr/local/lib/python2.7/dist-packages/elasticsearch/client/utils.py", line 69, in \_wrapped  
return func(\*args, params=params, \*\*kwargs)  
TypeError: get() got multiple values for keyword argument 'id'

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 9, 2015, 7:11am UTC](https://discuss.elastic.co/t/elasticsearch-py-index-and-get-errors/34124/2 "2015-11-09T07:11:59Z")

</div>

By mixing positional and keyword arguments you are effectively supplying the `id` argument twice. Here's the definition of the get() call:

[https://github.com/elastic/elasticsearch-py/blob/2.1.0/elasticsearch/client/](https://github.com/elastic/elasticsearch-py/blob/2.1.0/elasticsearch/client/) **init**.py#L296

Note how `id` is the second positional argument, so you're actually passing "html" as the id, and then you're passing `id` again as a keyword arguments.

[The documentation](https://elasticsearch-py.readthedocs.org/en/master/api.html#elasticsearch.Elasticsearch.get) doesn't list any positional arguments at all, only keyword arguments, so you should only use keyword arguments.

---

<div class="post-metadata">

**Author:** ![pstarrett1](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@pstarrett1](https://discuss.elastic.co/u/pstarrett1)\
**Post date:** [November 12, 2015, 10:38pm UTC](https://discuss.elastic.co/t/elasticsearch-py-index-and-get-errors/34124/3 "2015-11-12T22:38:45Z")

</div>

Magnus, yes, that was the trick. I am calling the fields by name. Actually, I found that I also was not properly calling the doc ID. I was calling id='1' when ES was supplying the doc ID. Once I got the correct ID, it returns the doc. Thank you very much!

---

<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:38pm UTC](https://discuss.elastic.co/t/elasticsearch-py-index-and-get-errors/34124/4 "2017-07-05T23:38:47Z")

</div>


