Search code examples
pythonelasticsearchelastic-stackelasticsearch-py

Elasticsearch-py Index takes 4 arguments, 5 given?


I have the following call to the Elasticsearch-py client:

esClient.index(index=data['AppName'], id=data['RequestId'], body=data)

I get the following error when I run my code:

Traceback (most recent call last):
   File "C:\Users\danielschnoll\dashboard\backend.py", line 52, in main
      parseData(sowSet)
   File "C:\Users\danielschnoll\dashboard\backend.py", line 36, in parseData
      sendToElasticSearch(d)
   File "C:\Users\danielschnoll\dashboard\backend.py", line 39, in sendToElasticSearch
      esClient.index(data['AppName'], id=data['RequestId'], body=data)
   File "C:\elasticsearch-6.2.0-py2.7.egg\elasticsearch\client\utils.py", line 76, in _wrapped
      return func(*args, params=params, **kwargs)
TypeError: index() takes at least 4 arguments (5 given)

I'm not really sure how I'm getting this error. My 4 arguments are the 'self' call from the esClient, and then the index, id, and body JSON object. Where is this supposed 5th argument and how do I remedy this? Thanks


Solution

  • The error is awkward and the documentation lacks an explanation.

    You won't make a mistake providing 5 or more arguments - it says at least - but you should provide your first argument index as the first positional argument and id as the second:

    esClient.index(data['AppName'], data['RequestId'], body=data)
    

    That's indirectly explained in the link provided just under your linked target in your comment from above, as there's no option to provide an index as an argument, only a direct call to PUT indexname/....