Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Use the `keyword` field for tags in related query (#3346)

Olga Bulatfcbc5197634c
diff --git a/api/api/controllers/elasticsearch/related.py b/api/api/controllers/elasticsearch/related.py
index 52f542acb..50d321695 100644
--- a/api/api/controllers/elasticsearch/related.py
+++ b/api/api/controllers/elasticsearch/related.py
@@ -50,7 +50,7 @@ def related_media(uuid: str, index: str, filter_dead: bool) -> list[Hit]:
# Only use the first 10 tags
if tags:
tags = [tag["name"] for tag in tags[:10]]
- related_query["should"].append(Q("terms", tags__name=tags))
+ related_query["should"].append(Q("terms", tags__name__keyword=tags))
# Exclude the dynamically disabled sources.
if excluded_providers_query := get_excluded_providers_query():
diff --git a/api/test/unit/controllers/elasticsearch/test_related.py b/api/test/unit/controllers/elasticsearch/test_related.py
index 31f7eeab6..abbb0bfa9 100644
--- a/api/test/unit/controllers/elasticsearch/test_related.py
+++ b/api/test/unit/controllers/elasticsearch/test_related.py
@@ -80,7 +80,7 @@ def test_related_media(
],
"should": [
{"match": {"title": "Bird Nature Photo"}},
- {"terms": {"tags.name": ["bird"]}},
+ {"terms": {"tags.name.keyword": ["bird"]}},
],
}
},