Created
May 13, 2025 05:26
-
-
Save jakwinkler/744be615d3b655e786de56cd22f9f749 to your computer and use it in GitHub Desktop.
Remove Ghost Indexes From ElasticSuite - Magento Open Source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ES_HOST="http://localhost:9200" # Replace with your ES host | |
INDEX_PATTERN="magento2_default_catalog_product_*" | |
# Get all aliases (used indexes) === | |
echo "Fetching all aliases in use..." | |
USED_INDEXES=$(curl -s "$ES_HOST/_cat/aliases?h=index" | sort | uniq) | |
# Get all indexes matching the pattern === | |
echo "Fetching all indexes matching pattern '$INDEX_PATTERN'..." | |
ALL_INDEXES=$(curl -s "$ES_HOST/_cat/indices?h=index" | grep "^$INDEX_PATTERN" | sort) | |
echo "Checking for ghost indexes to delete..." | |
for INDEX in $ALL_INDEXES; do | |
if ! echo "$USED_INDEXES" | grep -q "^$INDEX$"; then | |
echo "Deleting unused index: $INDEX" | |
curl -s -XDELETE "$ES_HOST/$INDEX" && echo " → Deleted" | |
else | |
echo "Skipping active index: $INDEX" | |
fi | |
done | |
echo "Cleanup complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment