This message was deleted.
# community-help
s
This message was deleted.
n
Copy code
client.collections.create({
    "name": "Company",
    "enable_nested_fields": True,
    "fields": [
        {
            "name": "id",
            "type": "string"
        },
        {
            "name": "market_value",
            "optional": True,
            "index": False,
            "type": "int64"
        }
    ]
})

docs = [
    {
        "id": "789",
        "market_value": 1000,
    },{
        "id": "777",
    },
    {
        "id": "999",
        "market_value": 400,
    },
    {
        "id": "111",
        "market_value": 50,
    },
    {
        "id": "222",
        "market_value": 5000,
    }
]

client.collections['Company'].documents.import_(docs)

client.collections['Company'].documents.search({"q": "*", "sort_by": "market_value:desc"})
Even if I use
client.collections['Company'].documents.search({"q": "*", "sort_by": "market_value(missing_values: last):desc"})
I get the same error:
Copy code
typesense.exceptions.ObjectNotFound: [Errno 404] Could not find a field named `market_value` in the schema for sorting.
k
Because the field is marked as index: false
n
Ok, sometimes I am forced to mark a field as index False when it is optional. Other times that is not the case. Can you point me to the docs which sheds some light on scenarios that are allowed to happen together or otherwise?
k
You can pretty much ignore the index property. It should work. We do currently restrict that a field which is set as index: false must also be optional: true.
If you don't set the index property there are no restrictions
n
Understood, thanks! I think I did set index False on some object/object[] types because I wanted the index only on the nested field which is when it complained of the optional. I see now why that was the case.