Repository navigation
Description
Query Information
PPL Command/Query:
source=opensearch_dashboards_sample_data_logs
| eval response_num=cast(response as int)
| where response_num >= 200 and response_num < 300
| regex tags='success'
| fields tags, response, request
Expected Result:
The query should return all documents where the tags array field contains the string "success" and the response code is between 200-299. Based on the sample data, there are thousands of documents matching this criteria.
Actual Result:
The query returns 0 rows (empty result set), even though documents with tags containing "success" exist in the index.
{
"datarows": [],
"total": 0,
"size": 0
}The same issue occurs with regex tags='warning', while regex tags='error' returns 761 rows as expected.
Dataset Information
Dataset/Schema Type
- OpenTelemetry (OTEL)
- Simple Schema for Observability (SS4O)
- Open Cybersecurity Schema Framework (OCSF)
- Custom (OpenSearch Dashboards sample data)
Index Mapping
{
"mappings": {
"properties": {
"tags": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"response": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"request": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
}
}
}
}Sample Data
{
"tags": ["success", "info"],
"response": 200,
"request": "/opensearch/opensearch-1.0.0.deb"
}Bug Description
Issue Summary:
The regex command fails to match patterns in array fields when the pattern does not match the first element of the array, even though the pattern exists in subsequent elements.
Steps to Reproduce:
- Load the OpenSearch Dashboards sample data (opensearch_dashboards_sample_data_logs)
- Execute the following query that works (matches the first array element):
source=opensearch_dashboards_sample_data_logs
| eval response_num=cast(response as int)
| where response_num >= 200 and response_num < 300
| regex tags='error'
| fields tags, response, request
Result: Returns 761 rows where tags = ["error", "info"]
- Execute the following query that fails (pattern exists but not as the first element):
source=opensearch_dashboards_sample_data_logs
| eval response_num=cast(response as int)
| where response_num >= 200 and response_num < 300
| regex tags='success'
| fields tags, response, request
Result: Returns 0 rows, even though thousands of documents have tags = ["success", "info"]
- Verify data exists:
source=opensearch_dashboards_sample_data_logs
| eval response_num=cast(response as int)
| where response_num >= 200 and response_num < 300
| fields tags, response, request
| head 10
Result: Shows documents with tags = ["success", "info"], ["warning", "info"], etc.
Impact:
This bug makes the regex command unreliable for filtering on array fields, as it only considers the first element of the array. This severely limits the usefulness of the regex command for log analysis and observability use cases where array fields are common (tags, labels, categories, etc.).
Environment Information
OpenSearch Version:
OpenSearch 3.3.0-SNAPSHOT
Additional Details:
- SQL Plugin version: 3.3.0-SNAPSHOT (built from main branch)
- The issue appears to be in the Calcite script execution layer
Preliminary Root Cause Analysis
Based on code analysis, the issue is in the CalciteScriptEngine.ScriptDataContext.get() method at:
./opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/CalciteScriptEngine.java:265
public Object get(String name) {
// ...
ScriptDocValues<?> docValue = this.docProvider.get(name);
if (docValue == null || docValue.isEmpty()) {
return null;
}
Object value = docValue.get(0); // <-- BUG: Only returns first element!
// ...
return value;
}When the regex command is executed on an array field like tags, the script accesses the field via doc values (keyword subfield). The get() method only returns docValue.get(0), which is the first element of the array. The REGEXP_CONTAINS function then only matches against this single value, ignoring all other elements in the array.
Why regex tags='error' works:
Documents with tags = ["error", "info"] have "error" as the first element, so the regex matches.
Why regex tags='success' fails:
Documents with tags = ["success", "info"] have "success" as the first element, but when accessed through doc values in the script, only the first value is returned and compared. However, the actual issue is more subtle - the field might be accessed differently depending on the field type and mapping.
Preliminary Proposed Fix
This is a preliminary analysis and requires further investigation:
The get() method in ScriptDataContext should handle multi-valued fields properly. When a field contains multiple values, the regex matching should either:
- Option A (Recommended): Check if the pattern matches ANY element in the array:
public Object get(String name) {
// ...
ScriptDocValues<?> docValue = this.docProvider.get(name);
if (docValue == null || docValue.isEmpty()) {
return null;
}
// For multi-valued fields, return all values or a representation
// that allows regex to match against any element
if (docValue.size() > 1) {
// Return a list or iterate through all values
return docValue; // Let the regex function handle the array
}
Object value = docValue.get(0);
// ...
return value;
}-
Option B: Modify the
REGEXP_CONTAINSimplementation to handle array inputs and match against any element. -
Option C: Use
getFromSource()instead of doc values for array fields to get the complete array, then match against all elements.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-]regex command fails to match patterns in array fields beyond first element[/-][+][BUG] `regex` command fails to match patterns in array fields beyond first element[/+]Fix regex/grok/patterns evaluation on array-backed fields (opensearch…
songkant-aws commentedon Apr 10, 2026
In the long-term, it should be resolved by this issue: #4984. Current OpenSearch DSL adopts schema-on-read but Calcite SQL is strong schema engine. Even we can fix this specific case by workaround, it won't fix other dynamic field issues.
I'll move bug label to enhancement.
qianheng-aws commentedon Apr 10, 2026
Closing as duplicate of #5333 — consolidated umbrella issue for array values not treated as atomic values.