# Python elasticsearch client : TypeError: index() got an unexpected keyword argument 'document'

**URL:** <https://discuss.elastic.co/t/python-elasticsearch-client-typeerror-index-got-an-unexpected-keyword-argument-document/308758>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [July 3, 2022, 6:28pm UTC](https://discuss.elastic.co/t/python-elasticsearch-client-typeerror-index-got-an-unexpected-keyword-argument-document/308758 "2022-07-03T18:28:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jay\_Urbain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jay_urbain/32/99133_2.png) [@Jay\_Urbain](https://discuss.elastic.co/u/Jay_Urbain)\
**Post date:** [July 3, 2022, 6:28pm UTC](https://discuss.elastic.co/t/python-elasticsearch-client-typeerror-index-got-an-unexpected-keyword-argument-document/308758/1 "2022-07-03T18:28:15Z")

</div>

elasticsearch: 8.3.1

python 3.9

Mac OS: Montery 12.4, ARM architecture.

Running the getting started example from elasticsearch docs ([Python Elasticsearch Client — Python Elasticsearch client 8.3.1 documentation](https://elasticsearch-py.readthedocs.io/en/v8.3.1/)) I'm getting got an unexpected keyword argument error on:  
-\> resp = es.index(index="test-index", id=1, document=doc)

Here's the code:

```python
from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()

doc = {
    'author': 'kimchy',
    'text': 'Elasticsearch: cool. bonsai cool.',
    'timestamp': datetime.now(),
}
resp = es.index(index="test-index", id=1, document=doc)
print(resp['result'])

resp = es.get(index="test-index", id=1)
print(resp['_source'])

es.indices.refresh(index="test-index")

resp = es.search(index="test-index", query={"match_all": {}})
print("Got %d Hits:" % resp['hits']['total']['value'])
for hit in resp['hits']['hits']:
    print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])`

```

I get the following error:

```auto
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [19], in <cell line: 10>()
      3 es = Elasticsearch()
      5 doc = {
      6 'author': 'kimchy',
      7 'text': 'Elasticsearch: cool. bonsai cool.',
      8 'timestamp': datetime.now(),
      9 }
---> 10 resp = es.index(index="test-index", id=1, document=doc)
     11 print(resp['result'])
     13 resp = es.get(index="test-index", id=1)

File ~/opt/miniconda3/envs/python_elk/lib/python3.8/site-packages/elasticsearch/client/utils.py:69, in query_params.<locals>._wrapper.<locals>._wrapped(*args, **kwargs)
     67 if p in kwargs:
     68 params[p] = kwargs.pop(p)
---> 69 return func(*args, params=params, **kwargs)
/>
TypeError: index() got an unexpected keyword argument 'document'

```

I've tried several different approaches.

Any direction would be appreciated.

Thanks,  
Jay

---

<div class="post-metadata">

**Author:** ![janjaarsma62](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@janjaarsma62](https://discuss.elastic.co/u/janjaarsma62)\
**Post date:** [July 8, 2022, 7:04am UTC](https://discuss.elastic.co/t/python-elasticsearch-client-typeerror-index-got-an-unexpected-keyword-argument-document/308758/2 "2022-07-08T07:04:34Z")

</div>

Hi Jay,

I had the same error. I changed "document" in "doc" so:  
resp = es.index(index="test-index", id=1, doc=doc)  
For me it worked.

regards,

Jan

---

<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:** [August 5, 2022, 7:28am UTC](https://discuss.elastic.co/t/python-elasticsearch-client-typeerror-index-got-an-unexpected-keyword-argument-document/308758/4 "2022-08-05T07:28:41Z")

</div>

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