TypeError: search() got an unexpected keyword argument 'doc_type' for elastic search version 5.6

Viewed 11814

I want to read the documents from a specific index and a specific type from elastic search. I construct the query:

es.search(index="document_index, doc_type="document_type", body={"query": {"match_all": {}}})['hits']['total']

I receive the error TypeError: search() got an unexpected keyword argument 'doc_type'. I went through a couple of links given below to look for a solution but everywhere the main answer is to downgrade the ES version. But our requirement is to keep ES version 5.6.

and a couple of more

Is there an alternative to mention the document type?

2 Answers

Seems your elasticsearch python client version is higher than v5.6. Remove the existing one with a doc_type compatible version e.g 5.5.3

Remove: pip uninstall elasticsearch and then Install pip install elasticsearch==5.5.3

N.B I'm suggesting to do that because elasticsearch doesn't support multiple doc types per index any more using doc_type

There is no another type. It is giving error due to different version

Yesterday I faced the same problem You need to check the elasticsearch version or You can directly download the version by this command: sudo pip install elasticsearch==version(e.g 6.3.1)

You can check current elastic version by this command - pip freeze

Related