Elasticsearch RAG - AI Playground - fix needed

Hello guys,

Thanks for sharing this amazing Elasticsearch RAG playground. It’s well prepared and easy to follow the instructions. There is a small bug in the last step, Export code => Install code dependencies part. The instruction says:

Run the following command in the terminal:

pip install elasticsearch
pip install openai

Everything is good so far, but

  • the out-of-box installed k8s elasticsearch node on version 8.14.1
  • pip install elasticsearch - it install dependencies for elasticsearch v9 as default

As a result it causes incompatibility error between the elasticsearch client and elasticsearch version, like the following.

root@host-1:~# python main.py
Traceback (most recent call last):
  File "/root/main.py", line 106, in <module>
    elasticsearch_results = get_elasticsearch_results(question)
  File "/root/main.py", line 71, in get_elasticsearch_results
    result = es_client.search(index="distributed-systems", body=es_query)
  File "/usr/local/lib/python3.9/dist-packages/elasticsearch/_sync/client/utils.py", line 421, in wrapped
    return api(*args, **kwargs)
  File "/usr/local/lib/python3.9/dist-packages/elasticsearch/_sync/client/__init__.py", line 4809, in search
    return self.perform_request(  # type: ignore[return-value]
  File "/usr/local/lib/python3.9/dist-packages/elasticsearch/_sync/client/_base.py", line 271, in perform_request
    response = self._perform_request(
  File "/usr/local/lib/python3.9/dist-packages/elasticsearch/_sync/client/_base.py", line 351, in _perform_request
    raise HTTP_EXCEPTIONS.get(meta.status, ApiError)(
elasticsearch.BadRequestError: BadRequestError(400, 'media_type_header_exception', 'Invalid media-type value on headers [Accept, Content-Type]', Accept version must be either version 8 or 7, but found 9. Accept=application/vnd.elasticsearch+json; compatible-with=9)

As a workaround, I installed the elasticsearch client version 8 with the following command pip install "elasticsearch>=8,<9" and it worked.