From f290fec6c133adfac463e7a6c572bbd1bfea2266 Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Fri, 13 Oct 2023 17:49:06 -0700 Subject: [PATCH] add fields param in toxcontent() for doc level query (#549) Signed-off-by: Surya Sashank Nistala --- .../commons/alerting/model/DocLevelQuery.kt | 1 + .../commons/alerting/model/XContentTests.kt | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelQuery.kt b/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelQuery.kt index 723438fe..9574b602 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelQuery.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelQuery.kt @@ -59,6 +59,7 @@ data class DocLevelQuery( builder.startObject() .field(QUERY_ID_FIELD, id) .field(NAME_FIELD, name) + .field(FIELDS_FIELD, fields.toTypedArray()) .field(QUERY_FIELD, query) .field(TAGS_FIELD, tags.toTypedArray()) .endObject() diff --git a/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt index a284c187..7c52ff42 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt @@ -417,6 +417,18 @@ class XContentTests { ) } + @Test + fun `test doc level query toXcontent`() { + val dlq = DocLevelQuery("id", "name", listOf("f1", "f2"), "query", listOf("t1", "t2")) + val dlqString = dlq.toXContent(builder(), ToXContent.EMPTY_PARAMS).string() + val parsedDlq = DocLevelQuery.parse(parser(dlqString)) + Assertions.assertEquals( + dlq, + parsedDlq, + "Round tripping Doc level query doesn't work" + ) + } + @Test fun `test alert parsing`() { val alert = randomAlert()