Python: ImportError: cannot import name 'E' from 'elasticsearch.esql'

I am reading the docs at ES|QL Query Builder | Python

There are examples that start with:

from elasticsearch.esql import ESQL, E

When I try these, I get:

ImportError: cannot import name 'E' from 'elasticsearch.esql' 

I need this to preventing injection attacks. How do I fix this?

  • Elasticsearch version 9.1.2
  • Python Elasticsearch version 9.1.0
  • Python version 3.10.18

Hello @peter9

As per 9.0+ documentation : ES|QL Query Builder | Python

This functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.

We do not see any E function in the elasticsearch.esql :

Name: elasticsearch
Version: 9.1.0
Summary: Python client for Elasticsearch
>>> import elasticsearch.esql
>>> print(dir(elasticsearch.esql))
['ESQL', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'and_', 'esql', 'not_', 'or_']

Same example is not available in 8.19 documentation :

Thanks!!

Hi @Tortoise

The E function is referenced in the 8.19 documentation on the following pages:

I am currently running into this import issue on 8.19 as I would like to use ESQL for safe querying.

1 Like

@Tortoise @peter9 It looks like E can be imported from dsl:

>>> from elasticsearch.dsl import E
1 Like