This message was deleted.
# community-help
s
This message was deleted.
k
In Typesense a field can have only one type. So the types of children of object fields are stored in the schema and validated. If you define a person field as a type of object and then index an object with a person.name string field, this information is added to the schema so that we can ensure that future person.name values are also string.
n
Thanks. I re-read the docs and I think I understand now. I ran into some other issues with the data I was importing and the schema expectations.
Can you help me with how I should configure the schema for this case: Schema
Copy code
{
    "name": "Company",
    "enable_nested_fields": True,
    "fields": [
        {
            "name": "id",
            "type": "string"
        },
        {
            "name": "persons",
            "type": "object[]",
            "index": False,
            "optional": True,
        },
        {
            "name": "persons.id",
            "type": "int64[]"
        },
        {
            "name": "persons.addresses.zip",
            "type": "string[]"
        }
    ]
}
When I try to import the following docs typesense complain:
Copy code
[
    {
        "id": "131415",
        "persons": []
    },
    {
        "id": "789",
        "persons": [
            {
                "id": 1,
                "addresses": [{"zip": None}]
            },
            {
                "id": 2,
                "addresses": [{"zip": "11112"}]
            },
            {
                "id": 3,
                "addresses": [{"zip": "11113"}]
            }
        ]
    },{
        "id": "1011112",
        "persons": [
            {
                "id": 4,
                "addresses": [{"zip": "11111"}]
            },
            {
                "id": 5,
                "addresses": [{"zip": "11112"}]
            },
            {
                "id": 6,
                "addresses": [{"zip": "11115"}]
            }
        ]
    }
]
The errors:
Copy code
[{'code': 400, 'document': '{"id": "131415", "persons": []}', 'error': 'Field `persons.addresses.zip` has been declared in the schema, but is not found in the document.', 'success': False}]
I’ve also tried to mark the fields
persons.id
and
persons.addresses.zip
as
optional
but it still complains for the first two docs. Only when I provide all the necessary fields and none of them are
None
, like in the 3rd case, it works.
k
Let me try running that, but is there a reason for defining those child fields?
n
this is just a toy example. but I need to index these fields for faster search/filtering based on these properties.
k
The issue is this empty doc:
Copy code
{
        "id": "131415",
        "persons": []
    },
n
but I’ve marked
persons
as
optional
. Should I instead just use
{"id":131415}
when there are no
persons
?
btw,
{"id":131415}
this too does not work and still raises the same error
k
There is also:
Copy code
"addresses": [{"zip": None}]
n
yep, how should I configure the schema so that these cases can be still be added to typesense?
k
You have defined
persons
as optional but have explicit child reference which is not marked as optional, so the explicit child field paths get prirority.
Add
"optional": True,
to the child fields
And avoid having
None
n
let me give that a try.
adding
optional
to all nested fields helped. thanks! I’ll figure out how to deal with
None
👍 1