When I try to index a jason file using "es.helpers.bulk" the error "TypeError: pop expected at most 1 argument, got 2" is occurring

When I execute the following code the error "TypeError: pop expected at most 1 argument, got 2" is occuring, please provide solutions to fix this.

def creatdocs(filename,pdfcontent):
    docs = [{
            'content': paragraph,
            'meta': {
            'source': filename
            }   
        }for paragraph in pdfcontent
    ]
    yield docs
#calling the function:
helpers.bulk(es, creatdocs(filename,pdfcontent),index='indexname2')

Error:

Traceback (most recent call last):
  
 File "C:\Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 524, in bulk
    for ok, item in streaming_bulk(
  File "C:\Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 422, in streaming_bulk
    for bulk_data, bulk_actions in _chunk_actions(
  File "C:\Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 232, in _chunk_actions
    for action, data in actions:
  File "C:\Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 65, in expand_action
    op_type: str = data.pop("_op_type", "index")
TypeError: pop expected at most 1 argument, got 2

Version:
Python 3.10.7
Elasticsearch client 8.5.3
Elasticsearch server 8.5.3

Welcome!

I'm not sure but it looks like the header of each line is missing...

But the following code works well, if we call the "helpers.bulk()" next to the json,

def creatdocs(filename,pdfcontent):
    docs = [{
            'content': paragraph,
            'meta': {
            'source': filename
            }   
        }for paragraph in pdfcontent
    ]
helpers.bulk(es,docs,index='statutory2')

The error occurs only if we call the "helpers.bulk()" from outside of the function.

I did some analysis on the piece of code in the "action.py"
Python 3.10.7\lib\site-packages\elasticsearch\helpers\actions.py", line 65,


op_type: str = data.pop("_op_type", "index")

Created the following two lines of code and executed which produces the same error.

data=[{"Lion","Tiger","Giraffe",'Panda'}]
op_type: str = data.pop("_op_type", "index")

I tried many possibilities but no luck, please provide your idea or solution which will help me to fix this.

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