Skip to content

Conversation

@Waleed-Mujahid
Copy link

Problem

  • Facet configuration: 'language': {'field': 'language.raw', 'enabled': True}
  • URL parameter: selected_facets=language_exact:English
  • Backend extracted: field='language', value='English'
  • Filter applied: ESDSLQ('term', language='English')
  • Expected filter: ESDSLQ('term', **{'language.raw': 'English'})

The incorrect field name caused elasticsearch to query the analyzed
'language' field instead of the case-sensitive 'language.raw' keyword
field, resulting in no matches for capitalized values.

Solution

Modified FacetedFieldSearchFilterBackend.filter_by_facets() to use
the configured elasticsearch field name from field_facets[field]['field']
instead of the facet key when building elasticsearch term queries.

Testing

This fix ensures that URLs like:
/api/v1/search/course_runs/facets/?selected_facets=language_exact:English
now correctly filter results using the language.raw field instead of
failing due to case sensitivity mismatches.

@Waleed-Mujahid
Copy link
Author

@DawoudSheraz Hey can you run test this PR on your end?

@DawoudSheraz
Copy link
Contributor

@DawoudSheraz Hey can you run test this PR on your end?

I am not a committer or contributor of course-discovery anymore. Tagging @openedx/committers-course-discovery here

@UsamaSadiq
Copy link
Member

Approved.

When filtering by facets that use .raw fields (like language.raw), the
filter_by_facets method was incorrectly using the facet configuration
key instead of the actual elasticsearch field name, causing filters
to fail for case-sensitive .raw fields.
@Waleed-Mujahid Waleed-Mujahid force-pushed the waleed/fix-raw-fields-facets branch from 6d351d8 to bea73d1 Compare September 15, 2025 16:10
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.

4 participants