Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit a338674

Browse files
authored
Use exact match for multifield eg. name.keyword (#1436)
<!-- A note on testing your PR --> <!-- Basic unit test run is executed against each commit in the PR. If you want to run a full integration test suite, you can trigger it by commenting with '/run-integration-tests' or '/run-it' --> Fixes #1433
1 parent b29303c commit a338674

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

platform/parsers/elastic_query_dsl/query_parser.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,16 +1199,35 @@ func createSortColumn(fieldName, ordering string) (model.OrderByExpr, error) {
11991199
func ResolveField(ctx context.Context, fieldName string, schemaInstance schema.Schema) string {
12001200
// Alias resolution should occur *after* the query is parsed, not during the parsing
12011201

1202+
isKeyword := false
1203+
if strings.HasSuffix(fieldName, ".keyword") {
1204+
isKeyword = true
1205+
}
12021206
fieldName = strings.TrimSuffix(fieldName, ".keyword")
12031207
fieldName = strings.TrimSuffix(fieldName, ".text")
12041208

1209+
updateQuesmaType := func(fieldKey schema.FieldName) {
1210+
if schemaInstance.Fields != nil {
1211+
field := schemaInstance.Fields[fieldKey]
1212+
field.Type = schema.QuesmaTypeKeyword
1213+
schemaInstance.Fields[field.PropertyName] = field
1214+
}
1215+
}
1216+
12051217
if resolvedField, ok := schemaInstance.ResolveField(fieldName); ok {
1218+
if isKeyword {
1219+
updateQuesmaType(schema.FieldName(fieldName))
1220+
}
12061221
return resolvedField.InternalPropertyName.AsString()
12071222
} else {
12081223
if fieldName != "*" && fieldName != "_all" && fieldName != "_doc" && fieldName != "_id" && fieldName != "_index" {
12091224
logger.DebugWithCtx(ctx).Msgf("field '%s' referenced, but not found in schema, falling back to original name", fieldName)
12101225
}
1211-
1226+
if isKeyword {
1227+
if fieldKey, exists := schemaInstance.ResolveFieldByInternalName(fieldName); exists {
1228+
updateQuesmaType(fieldKey.PropertyName)
1229+
}
1230+
}
12121231
return fieldName
12131232
}
12141233
}

platform/testdata/requests.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ var TestsSearch = []SearchTestCase{
11331133
}`,
11341134
[]string{`"host_name" __quesma_match '%prometheus%'`},
11351135
model.ListAllFields,
1136-
[]string{`SELECT "message" FROM ` + TableName + ` WHERE "host_name" ILIKE '%prometheus%' LIMIT 10`},
1136+
[]string{`SELECT "message" FROM ` + TableName + ` WHERE "host_name"='%prometheus%' LIMIT 10`},
11371137
[]string{},
11381138
},
11391139
{ // [6]
@@ -1712,7 +1712,7 @@ var TestsSearch = []SearchTestCase{
17121712
"stream_namespace" AS "aggr__suggestions__key_0",
17131713
count(*) AS "aggr__suggestions__count"
17141714
FROM __quesma_table_name
1715-
WHERE (("message" ILIKE '%User logged out%' AND "host_name" ILIKE '%poseidon%')
1715+
WHERE (("message" ILIKE '%User logged out%' AND "host_name"='%poseidon%')
17161716
AND ("@timestamp">=fromUnixTimestamp64Milli(1706542596491) AND "@timestamp"<=fromUnixTimestamp64Milli(1706551896491)))
17171717
GROUP BY "stream_namespace" AS "aggr__suggestions__key_0"
17181718
ORDER BY "aggr__suggestions__count" DESC, "aggr__suggestions__key_0" ASC
@@ -1870,7 +1870,7 @@ var TestsSearch = []SearchTestCase{
18701870
"namespace" AS "aggr__suggestions__key_0",
18711871
count(*) AS "aggr__suggestions__count"
18721872
FROM __quesma_table_name
1873-
WHERE (("message" ILIKE '%User logged out%' AND "host_name" ILIKE '%poseidon%')
1873+
WHERE (("message" ILIKE '%User logged out%' AND "host_name"='%poseidon%')
18741874
AND ("@timestamp">=fromUnixTimestamp64Milli(1706542596491) AND "@timestamp"<=fromUnixTimestamp64Milli(1706551896491)))
18751875
GROUP BY "namespace" AS "aggr__suggestions__key_0"
18761876
ORDER BY "aggr__suggestions__count" DESC, "aggr__suggestions__key_0" ASC

0 commit comments

Comments
 (0)