This message was deleted.
# community-help
s
This message was deleted.
n
Consider the schema:
Copy code
{
    "name": "Company",
    "enable_nested_fields": True,
    "fields": [
        {
            "name": "id",
            "type": "string"
        },
        {
            "name": "persons",
            "type": "object[]",
            "optional": True,
            "index": False,
        },
        {
            "name": "persons.id",
            "type": "string[]",
            "optional": True,
            "facet": True,
        },
        {
            "name": "persons.type",
            "type": "string[]"
        }
    ]
}
the
persons.id
is my facet field. Say I have persons of type
A
,
B
and
C
. But I’d like to get facet counts for only those persons say of type
A
?
A follow up to this would be if I can facet by an
object
type field. I tried this basic example and got no facets.
Copy code
client.collections.create({
    "name": "Company",
    "enable_nested_fields": True,
    "fields": [
        {
            "name": "id",
            "type": "string"
        },
        {
            "name": "persons",
            "type": "object[]",
            "optional": True,
            "facet": True
        },
        {
            "name": "id",
            "type": "string[]",
            "optional": True,
        },
        {
            "name": "type",
            "type": "string[]",
            "optional": True,
        }
    ]
})
client.collections['Company'].documents.import_([
    {
        "id": "789",
        "persons": [
            {"id": 1, "name": "ABC"},
            {"id": 21, "name": "DEF"}
        ],
    },{
        "id": "123",
        "persons": [
            {"id": 1, "name": "ABC"},
            {"id": 321, "name": "GHI"}
        ],
    },{
        "id": "456",
        "persons": [
            {"id": 4, "name": "JKL"},
            {"id": 21, "name": "DEF"}
        ],
    }
])
client.multi_search.perform({"searches":[{"collection": 'Company', "q": "*", "facet_by": "persons"}]}, {})
However if I do:
Copy code
client.multi_search.perform({"searches":[{"collection": 'Company', "q": "*", "facet_by": "persons.id"}]}, {})
I do get results as expected.
j
But I’d like to get facet counts for only those persons say of type A
You would apply a
filter_by
that filters results to only type A, and when you also facet on that query, you should only see facet counts for records of type A
A follow up to this would be if I can facet by an object type field.
We just added this feature this week in an RC build: https://github.com/typesense/typesense/issues/943#issuecomment-1733613491
❤️ 1