4

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

danielschnoll
  • 1,702
  • 3
  • 15
  • 28

1 Answers1

1

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/....

ipaleka
  • 3,055
  • 2
  • 6
  • 28
  • 2
    Does this mean that the call signature in the reathedocs docs is wrong? – Chillie Jul 15 '19 at 15:42
  • Yes, it was driving me mad last year... XD – ipaleka Jul 15 '19 at 15:43
  • 1
    this still didn't resolve the issue. I've updated my post question with the full stack trace. Even with the removed "index=" part of the kwargs I still get the error. – danielschnoll Jul 15 '19 at 16:05
  • Have you tried with the id value as an positional argument too? – ipaleka Jul 15 '19 at 16:11
  • 1
    that appears to have fixed it! now I have some further debugging to do with the rest of my code, but I don't get that index error anymore. I endorsed your answer, you should update it with the id part so others have that as a reference. thanks! – danielschnoll Jul 15 '19 at 16:15