Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support query_string for rollup search #438

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.opensearch.index.query.DisMaxQueryBuilder
import org.opensearch.index.query.MatchAllQueryBuilder
import org.opensearch.index.query.MatchPhraseQueryBuilder
import org.opensearch.index.query.QueryBuilder
import org.opensearch.index.query.QueryStringQueryBuilder
import org.opensearch.index.query.RangeQueryBuilder
import org.opensearch.index.query.TermQueryBuilder
import org.opensearch.index.query.TermsQueryBuilder
Expand Down Expand Up @@ -209,8 +210,11 @@ class RollupInterceptor(
}
fieldMappings.add(RollupFieldMapping(RollupFieldMapping.Companion.FieldType.DIMENSION, query.fieldName(), Dimension.Type.TERMS.type))
}
is QueryStringQueryBuilder -> {
// parse the query
}
else -> {
throw IllegalArgumentException("The ${query.name} query is currently not supported in rollups")
throw IllegalArgumentException("The ${query.name} query is currently not supported for rollup search.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.opensearch.index.query.DisMaxQueryBuilder
import org.opensearch.index.query.MatchAllQueryBuilder
import org.opensearch.index.query.MatchPhraseQueryBuilder
import org.opensearch.index.query.QueryBuilder
import org.opensearch.index.query.QueryStringQueryBuilder
import org.opensearch.index.query.RangeQueryBuilder
import org.opensearch.index.query.TermQueryBuilder
import org.opensearch.index.query.TermsQueryBuilder
Expand Down Expand Up @@ -358,6 +359,11 @@ fun Rollup.rewriteQueryBuilder(queryBuilder: QueryBuilder, fieldNameMappingTypeM
newMatchPhraseQueryBuilder.queryName(queryBuilder.queryName())
newMatchPhraseQueryBuilder.boost(queryBuilder.boost())
}
is QueryStringQueryBuilder -> {
queryBuilder
// For future specification
}

// We do nothing otherwise, the validation logic should have already verified so not throwing an exception
else -> queryBuilder
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,36 @@ class RollupInterceptorIT : RollupRestTestCase() {
rollupAggRes.getValue("min_passenger_count")["value"]
)

// query_string query
req = """
{
"size": 0,
"query": {
"query_string": {
"query": "8947"
}
},
"aggs": {
"min_passenger_count": {
"sum": {
"field": "passenger_count"
}
}
}
}
""".trimIndent()
rawRes = client().makeRequest("POST", "/source_rollup_search/_search", emptyMap(), StringEntity(req, ContentType.APPLICATION_JSON))
assertTrue(rawRes.restStatus() == RestStatus.OK)
rollupRes = client().makeRequest("POST", "/target_rollup_search/_search", emptyMap(), StringEntity(req, ContentType.APPLICATION_JSON))
assertTrue(rollupRes.restStatus() == RestStatus.OK)
rawAggRes = rawRes.asMap()["aggregations"] as Map<String, Map<String, Any>>
rollupAggRes = rollupRes.asMap()["aggregations"] as Map<String, Map<String, Any>>
assertEquals(
"Source and rollup index did not return same min results",
rawAggRes.getValue("min_passenger_count")["value"],
rollupAggRes.getValue("min_passenger_count")["value"]
)

// Unsupported query
req = """
{
Expand All @@ -348,7 +378,7 @@ class RollupInterceptorIT : RollupRestTestCase() {
} catch (e: ResponseException) {
assertEquals(
"Wrong error message",
"The match query is currently not supported in rollups",
"The match query is currently not supported for rollup search.",
(e.response.asMap() as Map<String, Map<String, Map<String, String>>>)["error"]!!["caused_by"]!!["reason"]
)
assertEquals("Unexpected status", RestStatus.BAD_REQUEST, e.response.restStatus())
Expand Down