Resolving Float Value Issues in PHP and Typesense.
TLDR Zildjian was having issues with float values being treated as int64 in Typesense. Kishore Nallan identified and rectified the issue, guiding the user through a software upgrade process.
1
1
Jul 20, 2023 (2 months ago)
Zildjian
05:27 AMthe field is an object and each field inside it should be a float (see screenshot). however when I do an import and encountered the scenario where values are a whole number but a float type in PHP, it automatically sets the field type as int64 on ts.
I would appreciate any answers/help. Thank you :bow:
with decimals
value: 123.2564
value when cast to float: (float) 123.2564 = 123.2564
type on php: float
value when passed to ts: 123.2564
type when passed to ts: float
ts treats this as: float
without decimals/whole number
value: 123
value when cast to float: (float) 123 = 123 (same result even if using round or number_format)
type on php: float
value when passed to ts: 123
type when passed to ts: float
ts treats this as: int64
Kishore Nallan
05:29 AMKishore Nallan
05:30 AMtypesense/typesense:0.25.0.rc48
build.Kishore Nallan
05:33 AMfields
should be part of the collection schema but in the PHP code it seems to be part of regularPrice
object field.Zildjian
01:38 PMso when returned on the document it should have something like this
{
// other properties
"regularPrice": {
"AUD": 20.20,
"NZD": 20.00,
"USD": 12.00,
}
}
Kishore Nallan
01:43 PMZildjian
01:45 PMthen all other document's regularPrice.AUD should be int64. now the problem I have is that some documents are floats and this will error out when importing those documents
Zildjian
01:46 PMKishore Nallan
01:53 PMregularPrice.*
Kishore Nallan
01:53 PMfloat
Zildjian
02:03 PMZildjian
02:03 PMJul 21, 2023 (2 months ago)
Zildjian
01:20 AMKishore Nallan
01:51 AMZildjian
02:50 AMKishore Nallan
03:01 AM1. Creating a collection with a schema with 1 or 2 fileds
2. A sample document ingested that causes the error
With the above it will be easy for me to reproduce what's happening. You can use curl as well, see an example here: https://gist.github.com/kishorenc/865511899735ab23d82b29d8592751c5
Zildjian
06:17 AMexport TYPESENSE_API_KEY=REDACTED
export TYPESENSE_HOST=REDACTED
export TYPESENSE_COLLECTION_NAME=test_products
curl -k "${TYPESENSE_HOST}/collections" -X POST -H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
"name": "test_products",
"fields": [
{"name": "regularPrice.*", "type": "float"},
{"name": "title", "type": "string"}
],
"enable_nested_fields": true
}'
curl "${TYPESENSE_HOST}/collections/${TYPESENSE_COLLECTION_NAME}/documents" -X POST \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{"title": "Product 1", "regularPrice": { "AUD": 1, "NZD": 2.2 }}'
curl "${TYPESENSE_HOST}/collections/${TYPESENSE_COLLECTION_NAME}/documents" -X POST \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{"title": "Product 1", "regularPrice": { "AUD": 1.0, "NZD": 2.2 }}'
Kishore Nallan
06:18 AMZildjian
06:19 AMJul 23, 2023 (2 months ago)
Zildjian
11:09 PMJul 24, 2023 (2 months ago)
Kishore Nallan
03:28 AM1
Jul 25, 2023 (2 months ago)
Kishore Nallan
02:49 AMZildjian
02:50 AMKishore Nallan
02:50 AMZildjian
02:57 AMKishore Nallan
02:57 AM0.25.0.rc54
versionZildjian
02:58 AM1
Zildjian
04:00 AMKishore Nallan
04:05 AMTypesense
Indexed 2776 threads (79% resolved)
Similar Threads
Troubleshooting Typesense Connection Issue and Data Retrieval
Felix encountered issues connecting to a server-created typesense and retrieving data collections. Kishore Nallan and Jason provided guidance, highlighting errors in the original code and suggesting changes to the URL and curl command.
Troubleshooting 400 Error When Upgrading Typesense Firestore Extension
Orion experienced a `400` error after updating the Typesense Firestore extension, causing issues with cloud functions. They traced the issue back to a data type conflict in their Typesense collection schema after updating. With help from Jason and Kishore Nallan, they resolved the issue by recreating the collection.
Syncing Data to Typesense Cloud Issue
Jameshwart had a problem syncing data to Typesense Cloud. Kishore Nallan provided a fix to this issue by doing an upgrade in the UI. Zildjian confirmed that they were working on the same project as Jameshwart and that the fix should work.
Cold Start Problem with Dynamic Collections
Adrian reported cold start issues with dynamic collections. Jason suggested using wildcard `*` for query_by parameters, upgrading to `0.25.0.rc34`, and clarified conventions. Adrian's issues were resolved but they reported a limitation that will potentially be addressed.
Fixing Corrupted Documents and Upgrading Typesense Cloud Version
gab had issues with corrupted documents in Typesense Cloud. Jason suggested upgrading to version 0.24.1.rc, which resolved the issue. They also discussed CORS domain management.