From 0693804505cd516aea80638fcb7a349449868512 Mon Sep 17 00:00:00 2001 From: Petar Dzepina Date: Tue, 3 Jan 2023 22:27:18 +0100 Subject: [PATCH] added test for falling back on index settings default_field Signed-off-by: Petar Dzepina --- .../rollup/interceptor/RollupInterceptorIT.kt | 78 ++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptorIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptorIT.kt index 2f8a3ece8..c47a81f0a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptorIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/rollup/interceptor/RollupInterceptorIT.kt @@ -1277,7 +1277,7 @@ class RollupInterceptorIT : RollupRestTestCase() { ) } - fun `test roll up search query_string query with missing fields and default_field`() { + fun `test roll up search query_string query with missing fields in fields and default_field`() { val sourceIndex = "source_rollup_search_qsq_2" val targetIndex = "target_rollup_qsq_search_2" @@ -1411,6 +1411,82 @@ class RollupInterceptorIT : RollupRestTestCase() { } catch (e: ResponseException) { assertTrue(e.message?.contains("[missing field test.fff]") ?: false) } + + // no fields or default_field present. Fallback on index setting [index.query.default_field] default value: "*" + req = """ + { + "size": 0, + "query": { + "query_string": { + "query": "state:TX AND state_ext:CA AND 12345" + } + + }, + "aggs": { + "earnings_total": { + "sum": { + "field": "earnings" + } + } + } + } + """.trimIndent() + try { + client().makeRequest("POST", "/$targetIndex/_search", emptyMap(), StringEntity(req, ContentType.APPLICATION_JSON)) + } catch (e: ResponseException) { + assertTrue( + e.message?.contains( + "[missing terms grouping on earnings, missing terms grouping on event_ts, missing field test.vvv, missing field test.fff]" + ) ?: false + ) + } + + // fallback on index settings index.query.default_field:state_ordinal + client().makeRequest( + "PUT", "$sourceIndex/_settings", + StringEntity( + """ + { + "index": { + "query": { + "default_field":"state_ordinal" + } + } + } + """.trimIndent(), + ContentType.APPLICATION_JSON + ) + ) + + req = """ + { + "size": 0, + "query": { + "query_string": { + "query": "state:TX AND state_ext:CA AND 7" + } + + }, + "aggs": { + "earnings_total": { + "sum": { + "field": "earnings" + } + } + } + } + """.trimIndent() + val rawRes = client().makeRequest("POST", "/$sourceIndex/_search", emptyMap(), StringEntity(req, ContentType.APPLICATION_JSON)) + assertTrue(rawRes.restStatus() == RestStatus.OK) + val rollupRes = client().makeRequest("POST", "/$targetIndex/_search", emptyMap(), StringEntity(req, ContentType.APPLICATION_JSON)) + assertTrue(rollupRes.restStatus() == RestStatus.OK) + val rawAggRes = rawRes.asMap()["aggregations"] as Map> + val rollupAggRes = rollupRes.asMap()["aggregations"] as Map> + assertEquals( + "Source and rollup index did not return same min results", + rawAggRes.getValue("earnings_total")["value"], + rollupAggRes.getValue("earnings_total")["value"] + ) } fun `test roll up search query_string query invalid query`() {