Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataFrame(serverless_client) fails with TypeError: 'Elasticsearch' object is not iterable #686

Open
pquentin opened this issue Apr 12, 2024 · 0 comments
Labels
good first issue Good for newcomers

Comments

@pquentin
Copy link
Member

pquentin commented Apr 12, 2024

Nick C on the Community Slack reported a bug when using DataFrame with an existing serverless Elasticsearch Python client.

from elasticsearch_serverless import Elasticsearch
import eland as ed
es = Elasticsearch(stuff)
print(es.info())  # <--- shows client connected successfully
df = ed.DataFrame(es, es_index_pattern=".ds-logs-endpoint.events*")

This fails with TypeError: 'Elasticsearch' object is not iterable because ensure_es_client tries to wrap the client in another one:

eland/eland/common.py

Lines 307 to 314 in 9cea238

def ensure_es_client(
es_client: Union[str, List[str], Tuple[str, ...], Elasticsearch]
) -> Elasticsearch:
if isinstance(es_client, tuple):
es_client = list(es_client)
if not isinstance(es_client, Elasticsearch):
es_client = Elasticsearch(es_client)
return es_client

The fix is probably to switch the isinstance check to check for str/list[str] instead of trying to check that it's not a client.

The workaround is to either pass connection data to DataFrame directly, or pass it a standard Elasticsearch client (useful to set credentials or other options).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant