Slackbot
09/28/2023, 8:00 AMNarayan Acharya
09/28/2023, 8:02 AM{
"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 ?Narayan Acharya
09/28/2023, 8:27 AMobject type field. I tried this basic example and got no facets.
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"}]}, {})Narayan Acharya
09/28/2023, 8:29 AMclient.multi_search.perform({"searches":[{"collection": 'Company', "q": "*", "facet_by": "persons.id"}]}, {})
I do get results as expected.Jason Bosco
09/28/2023, 4:25 PMBut I’d like to get facet counts for only those persons say of type AYou 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 AJason Bosco
09/28/2023, 4:27 PMA 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