aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
88 stars 76 forks source link

GraphQL property of type Float creates a mappings type Long in OpenSearch when uses the @searchable directive in mock #2683

Open Phok7 opened 2 months ago

Phok7 commented 2 months ago

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v18.13.0

Amplify CLI Version

12.12.4

What operating system are you using?

Ubuntu 22.04

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made.

Describe the bug

Hello!

I have a model in my schema.graphql with a property named Value of Float type.

type MeasurementValue @searchable @model {
  id: ID!
  Time: String
  Value: Float
}

When I try to make a aggregation query to get the sum or avg, for example, It returns a result with no float points.

Query:

query MyQuery {
  searchMeasurementValues(
    aggregates: {name: "sum", type: sum, field: Value}
  ) {
    nextToken
    total
    aggregateItems {
      name
      result {
        ... on SearchableAggregateScalarResult {
          __typename
          value
        }
      }
    }
  }
}

Result:

{
  "data": {
    "searchMeasurementValues": {
      "nextToken": "WyIwMmI4OTAxYS04MzczLTRmOWItYTM0NS04MjNjYmYyNTFlZTMiXQ==",
      "total": 86,
      "aggregateItems": [
        {
          "name": "sum",
          "result": {
            "__typename": "SearchableAggregateScalarResult",
            "value": 2344
          }
        }
      ]
    }
  }
}

If I do a GET measurementvalue/_mapping, this is the result:

{
  "measurementvalue" : {
    "mappings" : {
      "properties" : {
        "Time" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "Value" : {
          "type" : "long" <---- This type should be Float or Double
        },
        "__typename" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "createdAt" : {
          "type" : "date"
        },
        "id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "updatedAt" : {
          "type" : "date"
        }
      }
    }
  }
}

The type of the generated index in OpenSearch is long, nor float or double.

Thanks.

Expected behavior

The type of the generated index in OpenSearch should be float, not long.

Reproduction steps

  1. Create a model with the @searchable directive and a Float property.
  2. Make an aggregation query which requires number operations (sum, max, min, avg).

Project Identifier

No response

Log output

``` # Put your logs below this line ```

Additional information

No response

Before submitting, please confirm:

Phok7 commented 2 months ago

Sorry I forgot to say that this happens in mocked mode, in production is working fine. Sorry.

chriswaterbury commented 6 days ago

I see this happening in production if the first value saved is an integer even if the type is float.

Ex: first value saved to DynamoDB is 1, but in GraphQL schema it is declared as float. The OpenSearch mapping saves the index as having a type of Long for the field.