Skip to content

Conversation

1mustyz
Copy link

@1mustyz 1mustyz commented Jun 3, 2025

Fix Elasticsearch Client Deprecation Warnings and Import Issues

Overview

This PR addresses several compatibility issues in the Elasticsearch integration code to improve reliability and eliminate deprecation warnings.

Changes Made

1. 🔧 Fixed Elasticsearch Client Deprecation Warning

Issue: The body parameter in es_client.indices.create() is deprecated and will be removed in future versions.

Solution: Updated the code to use separate parameters for settings and mappings:

# Before (deprecated)
es_client.indices.create(index=index_name, body=index_settings)

# After (current best practice)
es_client.indices.create(
    index=index_name,
    settings=index_settings['settings'],
    mappings=index_settings['mappings']
)

2. ✅ Added Index Existence Check

Issue: Running the code multiple times would throw errors when trying to create an index that already exists.

Solution: Added a check to handle existing indices gracefully:

if not es_client.indices.exists(index=index_name):
    es_client.indices.create(
        index=index_name,
        settings=index_settings['settings'],
        mappings=index_settings['mappings']
    )
    print(f"Created index '{index_name}'")
else:
    print(f"Index '{index_name}' already exists")

3. 🐛 Fixed tqdm Import Issue

Issue: from tqdm.auto import tqdm was causing widget display errors in some environments.

Solution: Updated to use the standard tqdm import:

# Before (causing errors)
from tqdm.auto import tqdm

# After (stable)
from tqdm import tqdm

Benefits

  • ✨ Eliminates deprecation warnings for future-proofing
  • 🛡️ Prevents errors when re-running the code
  • 🔄 Improves code reliability and user experience
  • 📱 Fixes progress bar display issues across different environments

Testing

  • Verified index creation works on first run
  • Verified graceful handling when index already exists
  • Confirmed no deprecation warnings are displayed
  • Tested progress bar functionality

Compatibility

This change maintains backward compatibility while adopting current best practices for the Elasticsearch Python client.

@alexeygrigorev
Copy link
Member

There are many changes that are not relevant to the description - can you please remove them?

@alexeygrigorev
Copy link
Member

Also currently there's a conflict, please resolve it too. Thank you!

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

Successfully merging this pull request may close these issues.

2 participants