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) I'm getting got an unexpected keyword argument error on:
-> resp = es.index(index="test-index", id=1, document=doc)
Here's the code:
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:
---------------------------------------------------------------------------
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