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

fix: allow non-Elasticsearch search engines when reindexing courses [FC-0062] #35743

Merged
20 changes: 14 additions & 6 deletions cms/djangoapps/contentstore/management/commands/reindex_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import CourseLocator
from search.meilisearch import create_indexes, MeilisearchEngine, INDEX_FILTERABLES
from search.search_engine_base import SearchEngine

from cms.djangoapps.contentstore.courseware_index import CourseAboutSearchIndexer, CoursewareSearchIndexer
Expand Down Expand Up @@ -97,14 +98,21 @@ def handle(self, *args, **options): # pylint: disable=too-many-statements
logging.exception('Search Engine error - %s', exc)
return

index_exists = searcher._es.indices.exists(index=index_name) # pylint: disable=protected-access
# Meilisearch engine
pomegranited marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(searcher, MeilisearchEngine) and index_name in INDEX_FILTERABLES:
logging.info(f"Creating meilisearch index for {index_name}")
create_indexes({index_name: INDEX_FILTERABLES[index_name]})

index_mapping = searcher._es.indices.get_mapping( # pylint: disable=protected-access
index=index_name,
) if index_exists else {}
# Legacy Elasticsearch engine
else:
index_exists = searcher._es.indices.exists(index=index_name) # pylint: disable=protected-access

if index_exists and index_mapping:
return
index_mapping = searcher._es.indices.get_mapping( # pylint: disable=protected-access
index=index_name,
) if index_exists else {}

if index_exists and index_mapping:
return

# if reindexing is done during devstack setup step, don't prompt the user
if setup_option or query_yes_no(self.CONFIRMATION_PROMPT, default="no"):
Expand Down
Loading