Handling Null Fields in Schema
TLDR Ivan reported a bug regarding null fields in the schema. Kishore Nallan confirmed it as a bug, asked to file a Github report, and mentioned it was fixed in version 0.25.0.rc25.
1
1
Apr 28, 2023 (5 months ago)
Ivan
07:37 AM{
name: '...',
enable_nested_fields: true,
fields: [
{ name: 'test', type: 'object' },
{ name: 'test.entry1', type: 'string', facet: true, optional: true },
{ name: 'test.entry2', type: 'string', facet: true, optional: true },
...
]
}
Now If I query this collection a return object could look like this:
{
test: { entry1: 'something', entry2: null },
test.entry2: null
}
If the value of a field is
null
then it is added to the root of the return object as an additional property. E.g. test.entry2
in the example above.Has anyone else noticed this?
Kishore Nallan
07:42 AMIvan
09:37 AMIvan
09:38 AMconst schema = {
name: 'test',
enable_nested_fields: true,
fields: [
{ name: 'text', type: 'string' },
{ name: 'person', type: 'object' },
{ name: 'person.name', type: 'string', facet: true, optional: true },
{ name: 'person.age', type: 'string', facet: true, optional: true },
{ name: 'person.address', type: 'string', facet: true, optional: true },
]
}
const client = new Typesense.Client(...)
try {
await client.collections().create(schema)
} catch (err) {
...
}
const data = [
{ text: 'a', person: { name: null, age: null, address: null } },
{ text: 'b', person: { name: 'test', age: null, address: null } },
{ text: 'c', person: { name: null, age: 'test', address: null } },
{ text: 'd', person: { name: null, age: null, address: 'test' } }
]
try {
await client.collections(schema.name).documents().import(data)
} catch(err) {
...
}
Ivan
09:39 AM"hits": [
{
"document": {
"id": "3",
"person": {
"address": "test",
"age": null,
"name": null
},
"person.age": null,
"person.name": null,
"text": "d"
},
"highlight": {},
"highlights": []
},
{
"document": {
"id": "2",
"person": {
"address": null,
"age": "test",
"name": null
},
"person.address": null,
"person.name": null,
"text": "c"
},
"highlight": {},
"highlights": []
},
{
"document": {
"id": "1",
"person": {
"address": null,
"age": null,
"name": "test"
},
"person.address": null,
"person.age": null,
"text": "b"
},
"highlight": {},
"highlights": []
},
{
"document": {
"id": "0",
"person": {
"address": null,
"age": null,
"name": null
},
"person.address": null,
"person.age": null,
"person.name": null,
"text": "a"
},
"highlight": {},
"highlights": []
}
]
Kishore Nallan
09:44 AMIvan
09:58 AMKishore Nallan
09:59 AM1
Kishore Nallan
10:32 AM0.25.0.rc25
Ivan
12:32 PM1
Typesense
Indexed 2779 threads (79% resolved)
Similar Threads
Troubleshooting Typesense 400 Error with Null Fields
sonu was encountering a 400 error due to null fields during Typesense indexing. Jason suggested upgrading to a recent version, removing null fields, and marking potentially null fields as `optional: true`. gab shared a similar issue and workaround.
Resolving Error with Incorrect Field Type during Schema Update
Samuel encountered an error updating the schema for an existing collection. Kishore Nallan suggested specifying a concrete type, and later found inconsistent data within the collection that caused the error.
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.
Firestore to Typesense Backfill Issue with Dynamic Paths
Greg experienced issues with Firestore to Typesense backfill not working, and Jason determined it might be related to dynamic paths in Firestore collections not being supported. An RC version of the extension with dynamic path support was considered but needs further review before being shared with Greg.
Troubleshooting Invalid Field Error in Firestore Document Indexing
Darren receives an error when indexing Firestore documents with empty array in "_grades" field. Jason suggests submitting a bug report and manually setting the schema. The user still experiences issues. Kishore Nallan reproduces the bug, but suggests a solution might exist with an explicit 'string[]' type definition. Further investigation is needed.