Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.
Merged
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
21 changes: 20 additions & 1 deletion platform/parsers/elastic_query_dsl/query_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1199,16 +1199,35 @@ func createSortColumn(fieldName, ordering string) (model.OrderByExpr, error) {
func ResolveField(ctx context.Context, fieldName string, schemaInstance schema.Schema) string {
// Alias resolution should occur *after* the query is parsed, not during the parsing

isKeyword := false
if strings.HasSuffix(fieldName, ".keyword") {
isKeyword = true
}
fieldName = strings.TrimSuffix(fieldName, ".keyword")
fieldName = strings.TrimSuffix(fieldName, ".text")

updateQuesmaType := func(fieldKey schema.FieldName) {
if schemaInstance.Fields != nil {
field := schemaInstance.Fields[fieldKey]
field.Type = schema.QuesmaTypeKeyword
schemaInstance.Fields[field.PropertyName] = field
}
}

if resolvedField, ok := schemaInstance.ResolveField(fieldName); ok {
if isKeyword {
updateQuesmaType(schema.FieldName(fieldName))
}
return resolvedField.InternalPropertyName.AsString()
} else {
if fieldName != "*" && fieldName != "_all" && fieldName != "_doc" && fieldName != "_id" && fieldName != "_index" {
logger.DebugWithCtx(ctx).Msgf("field '%s' referenced, but not found in schema, falling back to original name", fieldName)
}

if isKeyword {
if fieldKey, exists := schemaInstance.ResolveFieldByInternalName(fieldName); exists {
updateQuesmaType(fieldKey.PropertyName)
}
}
return fieldName
}
}
Expand Down
6 changes: 3 additions & 3 deletions platform/testdata/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ var TestsSearch = []SearchTestCase{
}`,
[]string{`"host_name" __quesma_match '%prometheus%'`},
model.ListAllFields,
[]string{`SELECT "message" FROM ` + TableName + ` WHERE "host_name" ILIKE '%prometheus%' LIMIT 10`},
[]string{`SELECT "message" FROM ` + TableName + ` WHERE "host_name"='%prometheus%' LIMIT 10`},
[]string{},
},
{ // [6]
Expand Down Expand Up @@ -1712,7 +1712,7 @@ var TestsSearch = []SearchTestCase{
"stream_namespace" AS "aggr__suggestions__key_0",
count(*) AS "aggr__suggestions__count"
FROM __quesma_table_name
WHERE (("message" ILIKE '%User logged out%' AND "host_name" ILIKE '%poseidon%')
WHERE (("message" ILIKE '%User logged out%' AND "host_name"='%poseidon%')
AND ("@timestamp">=fromUnixTimestamp64Milli(1706542596491) AND "@timestamp"<=fromUnixTimestamp64Milli(1706551896491)))
GROUP BY "stream_namespace" AS "aggr__suggestions__key_0"
ORDER BY "aggr__suggestions__count" DESC, "aggr__suggestions__key_0" ASC
Expand Down Expand Up @@ -1870,7 +1870,7 @@ var TestsSearch = []SearchTestCase{
"namespace" AS "aggr__suggestions__key_0",
count(*) AS "aggr__suggestions__count"
FROM __quesma_table_name
WHERE (("message" ILIKE '%User logged out%' AND "host_name" ILIKE '%poseidon%')
WHERE (("message" ILIKE '%User logged out%' AND "host_name"='%poseidon%')
AND ("@timestamp">=fromUnixTimestamp64Milli(1706542596491) AND "@timestamp"<=fromUnixTimestamp64Milli(1706551896491)))
GROUP BY "namespace" AS "aggr__suggestions__key_0"
ORDER BY "aggr__suggestions__count" DESC, "aggr__suggestions__key_0" ASC
Expand Down
Loading