Skip to content

Commit

Permalink
added test for falling back on index settings default_field
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Dzepina <[email protected]>
  • Loading branch information
Petar Dzepina committed Jan 3, 2023
1 parent 491e5cc commit 0693804
Showing 1 changed file with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<String, Map<String, Any>>
val rollupAggRes = rollupRes.asMap()["aggregations"] as Map<String, Map<String, Any>>
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`() {
Expand Down

0 comments on commit 0693804

Please sign in to comment.