Author: nicolas.maillet-contoz <nicolas.maillet-contoz@infomaniak.com>
Date: Wed, 01 Oct 2025 11:18:01 +0200
Subject: Fix elasticsearch & opensearch requests
 Using list for metric_types in _build_must, in case it was not.
 The APIs expects a list for "type" in "terms".
Story: 2011541
Task: 52868
Signed-off-by: Nicolas Maillet-Contoz <nicolas.maillet-contoz@infomaniak.com>
Change-Id: Ia57e81dade3f54383d66a27c6935dda3779b090a
Origin: https://review.opendev.org/c/openstack/cloudkitty/+/962653
Last-Update: 2025-10-01

diff --git a/cloudkitty/storage/v2/elasticsearch/client.py b/cloudkitty/storage/v2/elasticsearch/client.py
index 98dc8a2..eb87934 100644
--- a/cloudkitty/storage/v2/elasticsearch/client.py
+++ b/cloudkitty/storage/v2/elasticsearch/client.py
@@ -78,6 +78,9 @@
             must.append({'term': {'type': filters['type']}})
 
         if metric_types:
+            if type(metric_types) is not list:
+                metric_types = [metric_types]
+
             must.append({"terms": {"type": metric_types}})
 
         return must
diff --git a/cloudkitty/storage/v2/opensearch/client.py b/cloudkitty/storage/v2/opensearch/client.py
index 868af2c..b46122e 100644
--- a/cloudkitty/storage/v2/opensearch/client.py
+++ b/cloudkitty/storage/v2/opensearch/client.py
@@ -78,6 +78,9 @@
             must.append({'term': {'type': filters['type']}})
 
         if metric_types:
+            if type(metric_types) is not list:
+                metric_types = [metric_types]
+
             must.append({"terms": {"type": metric_types}})
 
         return must
