Using Typesense to Query by Custom Column Key Value

TLDR Sandip asked how to use Typesense to perform unique key searches in different organizations. Kishore Nallan suggested creating an 'object' field for varying keys. After a clarification, Sandip expressed satisfaction with the advice.

Photo of Sandip
Sandip
Sat, 12 Aug 2023 06:28:39 UTC

Hi <@4L6c7>, Kishore Nallan I am using Typesense Multi-tenant functionality where I will create a scope search key for organizations and execute search queries using the scope key. But I have 1 column in the collection that have different key value for each organization. But Typesense collections do not support JSON type. How I fulfilled my requirement that I wanted to search documents based on custom column key value that I stored in one column name as "custom". below I mention an example that I have 2 organizations with document examples: orgA document for candidates collections: { "name": "john minati", "email":"", "custom":{ "location":"", "address":"" } } orgB document for candidate schema: { "name": "carry minati", "email":"", "custom":{ "salary":"", "linkedin":"" } } here my collection name is a candidates and one column value is different for each organization like custom, how do I fulfill my requirement that I wanted to execute a search key for orgA search by location and orgB search by LinkedIn?

Photo of Kishore Nallan
Kishore Nallan
Sun, 13 Aug 2023 08:14:27 UTC

You could have an `object` field which can contain different keys. ``` curl -k "" -X POST -H "Content-Type: application/json" \ -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{ "name": "docs", "enable_nested_fields": true, "fields": [ {"name":"custom","type":"object"} ] }'``` In the example above you can index a sub-field under the custom object and then during querying you just need to mention `query_by=custom` instead of specifying the child fields explicitly. We will search on the child fields on the `custom` object automatically.

Photo of Sandip
Sandip
Mon, 14 Aug 2023 05:10:19 UTC

object type not listed in Typesense doc.

Photo of Kishore Nallan
Kishore Nallan
Mon, 14 Aug 2023 05:18:01 UTC

Photo of Sandip
Sandip
Mon, 14 Aug 2023 05:20:38 UTC

Thanks Kishore Nallan :slightly_smiling_face: