Faceting Objects in Typesense
TLDR John wants to facet objects in Typesense, but faces issues. Kishore Nallan suggests creating a feature request on GitHub.


Mar 20, 2023 (6 months ago)
John
01:23 PMWe’re trying to use the nested fields to have a pretty color filter where we’d like to store something like
name="Blue", h=0, s=10, l=20
, facet by that, and then have the frontend nicely display the name along with the actual color. However, it doesn’t seem like faceting based on objects is working, you just get the empty string.Is this something you could implement support for or do we have to try to find a workaround? I imagine you could hash the objects and facet by that as a string under the hood or something. Code in thread.
John
01:23 PMimport json
import typesense
COLLECTION = "example"
client = typesense.Client(
{
"api_key": "TYPESENSEDEV",
"nodes": [{"host": "localhost", "port": "8108", "protocol": "http"}],
"connection_timeout_seconds": 2,
}
)
try:
client.collections[COLLECTION].delete()
except:
pass
fields = [
{
"name": "title",
"type": "string",
},
{
"name": "color",
"type": "object",
"facet": True,
},
]
client.collections.create(
{
"name": COLLECTION,
"fields": fields,
"enable_nested_fields": True,
}
)
products = [
{
"title": "foo",
"color": {
"name": "red",
"h": 0,
"s": 100,
"l": 50,
},
},
{
"title": "bar",
"color": {
"name": "blue",
"h": 240,
"s": 100,
"l": 50,
},
},
{
"title": "baz",
"color": {"name": "Multi-colored", "special_type": "multi"},
},
]
client.collections[COLLECTION].documents.import_(products, {"action": "create"})
facet_counts = client.collections[COLLECTION].documents.search(
{
"q": "*",
"facet_by": "color",
}
)["facet_counts"]
print(json.dumps(facet_counts, indent=4))
Kishore Nallan
01:24 PMcolor.*
in the facet_by?John
01:27 PMtypesense.exceptions.ObjectNotFound: [Errno 404] Could not find a facet field named `color.*` in the schema.
John
01:27 PMcolor.name
for example worksJohn
01:27 PMKishore Nallan
01:28 PMKishore Nallan
01:30 PM0.25.0.rc14
John
01:31 PMJohn
01:35 PM0.25.0.rc14
but it still seems to facet the fields independently, whereas what I’d want is something like{
"value": {"name": "blue", "rgb": "#123456"},
"count": 3
},
{
"value": {"name": "black", "rgb": "#000000"},
"count": 2
}
Kishore Nallan
01:40 PMJohn
01:43 PMSo in this case I could get that there’s 137 documents with Hue value 15, 49 documents with Hue value 19, 137 documents with Name value Blue et.c. But what I want is to know that there are 137 documents with {name=blue, hue=15, …}
Kishore Nallan
01:44 PMJohn
01:45 PMKishore Nallan
01:45 PMJohn
01:45 PMMar 21, 2023 (6 months ago)
Typesense
Indexed 2764 threads (79% resolved)
Similar Threads
Issues with Highlight Version in Typesense
Stefan reported issues with the new highlight version in Typesense. Kishore Nallan provided a temporary workaround and further fixed the issue with an updated build.
Updating Collections Strategy and Faceting New Field
Nithin asked about strategies for updating collections and faceting new fields. Kishore Nallan suggested creating another collection, indexing in the background and using aliases to switch live traffic over, and shared details about the upcoming release.
Typesense Filter Bug Involving Similar Facets
SamHendley reported a bug in Typesense where filtering by facet returns wrong documents, providing a reproduction case. Jason and Kishore Nallan recognized the issue, tracked it on GitHub, and implemented a fix in a new Docker build.

Faceting issue with Products Collections in Typesense
Carl was unable to facet on a string array. Kishore Nallan and Jason advised ensuring facet counts were being returned and offered to assist in troubleshooting. Issue resolved upon Carl realizing no data was saved in the database.



Accessing Nested Objects Using `query_by` in Typesense
Emma wanted to query nested objects using `query_by`. Kishore Nallan suggested using `title.*` pattern and ensuring `enable_nested_fields` is set to true.


