-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using Search query on a float field returning unexpected results. #866
Comments
Hi @jeff-accountably - It looks like you are using Amplify JS with react native. Please let me know if that is not the case. Otherwise I will transfer this to the Amplify JS repo. |
I am using Amplify JS with React JS, not react native. |
I am experiencing similar @searchable related error #1038 (maybe it's something with encoding ??) |
DescriptionThe problem could be reproduced and another error appeared in the process, in which AWSDate data would not be sortable or appear in the search results when using the Steps to reproduce errors
type Transaction @model @searchable {
id: ID!
name: String!
transactionDate: AWSDate
transactionTotalAmount: Float
}
mutation createIncorrect {
createTransaction(input: {name: "Lorem ipsum dolor sit amet",
transactionDate: "2010-09-28Z",
transactionTotalAmount: 123}) {
name
transactionDate
transactionTotalAmount
id
createdAt
updatedAt
}
} In your Amazon Open Source service you should see the following index being created:
query filterAndSort {
searchTransactions(filter: {transactionTotalAmount: {eq: 123}},
sort: {direction: desc, field: transactionDate}, limit: 10) {
total
items {
id
transactionDate
createdAt
transactionTotalAmount
}
}
} You should see the following result: {
"data": {
"searchTransactions": {
"total": null,
"items": []
}
}
} If you change the sort field to name like this: query filterAndSort {
searchTransactions(filter: {transactionTotalAmount: {eq: 123}},
sort: {direction: desc, field: name}, limit: 10) {
total
items {
id
transactionDate
createdAt
transactionTotalAmount
}
}
} You should now see the transaction you had created earlier. mutation create {
createTransaction(input: {name: "Lorem ipsum dolor sit amet",
transactionDate: "2010-09-28Z",
transactionTotalAmount: 123.15}) {
name
transactionDate
transactionTotalAmount
id
createdAt
updatedAt
}
} Run the previous query: query filterAndSort {
searchTransactions(filter: {transactionTotalAmount: {eq: 123}},
sort: {direction: desc, field: name}, limit: 10) {
total
items {
id
transactionDate
createdAt
transactionTotalAmount
}
}
} And you should see both the result for the first transaction and the second one, even though the second one doesn't have a How to solve itClone your current environment and be sure that the first element you insert has a transactionDate in the format YYYY-MM-DD. If you insert the Z at the end it will be parsed as text and won't let you sort by date, even if allowed by the AWSDate Scalar. Also be sure to insert a float not ending in .0 (such as 123.15) as the transactionTotalAmount. I tried to do it with 123.0 and it didn't work. It should work with the following query: mutation createCorrect {
createTransaction(input: {name: "Lorem ipsum dolor sit amet",
transactionDate: "2010-09-28",
transactionTotalAmount: 123.15}) {
name
transactionDate
transactionTotalAmount
id
createdAt
updatedAt
}
} You should see your new index as the one below:
The following query should work as expected now: query filterAndSort {
searchTransactions(filter: {transactionTotalAmount: {eq: 123.15}},
sort: {direction: desc, field: transactionDate}, limit: 10) {
total
items {
id
transactionDate
createdAt
transactionTotalAmount
}
}
} Also you should be able to insert other values without the number being a float or the not ending in .0 restriction. Persistent errorsIf an AWSDate is present you can create a transaction with a transactionDate with a timezone such as explained in the AppSync documentation (e.g "1970-01-01Z" or "1970-01-01+05:30"). Whenever this happens a new transaction gets created but the A solution to this is using AWSDateTime or String instead of AWSDate. Possible causes of the problemI think it has to tho with the way Amazon OpenSearch Service parses the data. The index is created in the OpenSearch instance based on the first data registry that is inserted (I think this is the case as an index doesn't exist before the data is inserted). Also, according to the OpenSearch documentation, there is no timezone offset in the |
Float numbers ending in .0 where being parsed as integers in an OpenSearch instance when using the @searchable directive. If this data was the first being uploaded to the instance, searching queries wouldn't work as expected. The change creates a JSON file which is uploaded with the Python streaming function to lambda. The JSON has all the schema data types of the @searchable model fields. A modified version of the Python streaming function enables the DynamoDB event fields to be correctly parsed to the correct data type described in the schema. ✅ Closes: aws-amplify#866
Thanks for the details in issue report and contribution! The current behavior for the data type in elastic search is depending on the first inserted data following the dynamic mapping rules here. This is not ideal in some cases as you point out for float and date type with timezone. While the PR fixes the float type, we are currently working on a more generic solution for all the data type dynamic mapping. Still the PR really helps a lot for us to get a clear picture of this issue! I will update with the solution once the team approves the proposal. |
Thanks @AaronZyLee. Also, my solution can be extended to other data types as well, it just needs to add conditions in the Python lambda function to map to the correct type. I would be glad to contribute to this fix as I have time to work on it. I am currently working with the Amplify Team via the MLHFellowship this fall, so reach out to me if you need anything. |
Description
Here is my example query code running in javascript on the client side.
My schema has the field as a float, and the model object is tagged with @searchable.
In my database I have a number of transactions that are 29.98, or 29.37, etc. They all get returned from this query, which is unexpected, since only 29 should be returned.
If I change the filter to be
transactionTotalAmount: { eq: 29.98 }
nothing gets returned, even though that should be an exact match with the transaction that is 29.98.Categories
Steps to Reproduce
No response
Screenshots
No response
Platforms
Android Device/Emulator API Level
No response
Environment
Dependencies
Device
N/A
OS
N/A
CLI Version
8.0.3
Additional Context
No response
The text was updated successfully, but these errors were encountered: