diff --git a/platform/parsers/elastic_query_dsl/query_parser.go b/platform/parsers/elastic_query_dsl/query_parser.go index 8eb0e795e..06c299b34 100644 --- a/platform/parsers/elastic_query_dsl/query_parser.go +++ b/platform/parsers/elastic_query_dsl/query_parser.go @@ -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 } } diff --git a/platform/testdata/requests.go b/platform/testdata/requests.go index 9f35e8eb0..d54ee18fc 100644 --- a/platform/testdata/requests.go +++ b/platform/testdata/requests.go @@ -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] @@ -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 @@ -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