#community-help

Handling Array of Objects for TypeSense

TLDR notyalc asked how to handle arrays in TypeSense; Andrew recommended having the data in TypeSense twice: flattened and non-flattened. The non-flattened version is displayed in the UI. Jason confirmed they'll document this approach and add future support for nested objects.

Powered by Struct AI

2

1

1

Dec 15, 2021 (25 months ago)
notyalc
Photo of md5-ba3d677abaf42c2497b8bbedfd718223
notyalc
05:37 PM
Hey all 👋

How should I go about shaping an array of objects for TypeSense? If I understand correctly, that data need to be flattened but I’m not sure how to reconstruct that back to it’s original shape for showing in our product UI.
05:40
notyalc
05:40 PM
Here’s an example:

const data = {
 userName: 'Clayton Ray',
 userLocation: 'Tampa, FL',
 schools: [
   { id: 'uuid.v4()', name: 'Harvard', grad: 1990 },
   { id: 'uuid.v4()', name: 'Yale', grad: 1995 },
  ]
}
Andrew
Photo of md5-88d88db4789daa0e3abef8c3ca27772b
Andrew
06:24 PM
Hiya. I'm not a member of the typesense team, but I will tell you how we solved this:
You can submit arrays of objects to typesense, as long as you dont want them indexed. So we have the data in typesense twice: flattened and non-flattened. We search in the flattened data but the UI displays the non-flattened. As I understand it the non-indexed data is stored on disk, so doesnt affect RAM requirements, just disk

1

notyalc
Photo of md5-ba3d677abaf42c2497b8bbedfd718223
notyalc
06:29 PM
Gotcha, interesting
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:01 PM
Interesting approach Andrew!
notyalc
Photo of md5-ba3d677abaf42c2497b8bbedfd718223
notyalc
07:02 PM
So seems like this is the recommended “official” way?
07:02
notyalc
07:02 PM
If so, would be nice to document that
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:03 PM
We didn't have an official recommended way so far, but this approach sounds reasonable to me. Will document it
07:04
Jason
07:04 PM
We're also planning to add native support for nested objects and arrays of objects in v0.24, so hopefully this workaround is not needed for too long
notyalc
Photo of md5-ba3d677abaf42c2497b8bbedfd718223
notyalc
07:06 PM
Gotcha. Is there any estimation you can give me? I’m rebuilding search right now but if it’s reasonable, I may hold off
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:06 PM
We're probably looking at Q2 2022 for 0.24

1

notyalc
Photo of md5-ba3d677abaf42c2497b8bbedfd718223
notyalc
07:06 PM
Appreciate it

1

07:07
notyalc
07:07 PM
Thanks Andrew for your solution!
Andrew
Photo of md5-88d88db4789daa0e3abef8c3ca27772b
Andrew
07:41 PM
Glad to help notyalc. I'd recommend starting with your Typsense project asap. It's an awesome product and I would imagine you can remove the workaround fairly easily when 0.24 comes out. (That's our plan anyway)

1

Typesense

Lightning-fast, open source search engine for everyone | Knowledge Base powered by Struct.AI

Indexed 3015 threads (79% resolved)

Join Our Community

Similar Threads

Typesense Bug Fix with `canceled_at` Field and Upgrade Concerns

Mateo reported an issue regarding the treatment of an optional field by Typesense which was confirmed a bug by Jason. After trying an upgrade, an error arose. Jason explained the bug was due to a recent change and proceeded to downgrade their version. Future upgrade protocols were discussed.

3

74
10mo

Trouble in Implementing Deeply Nested Search

Anirudh is struggling to implement a two-level nested search. Jason asked for some specific examples to study the issue. Anirudh provided some material, realizing that adding top fields helped but might over-index. Jason then suggested reporting this issue on GitHub.

2

21
3d

Issue with `included_fields` Command in Typesense

SamHendley encountered an issue with the `included_fields` command in Typesense versions 0.23.0 and 0.24.0.rc17. Jason helped identify it as a bug in the 0.24.X version, which was later addressed in release 0.24.0.rcn19.

16
14mo

Resolving Multilingual Search Function in Typesense Software

Bill is having difficulty with multilingual search functionality in Typesense software. Developer Kishore Nallan suggested setting a language locale and provided a demo build. The build solution had some issues, and after multiple rounds of software updates and troubleshooting, the problem still persists.

2

89
25mo

Upgrading Typesense to Solve Syntax Error

Ken encountered an issue with Typesense search enhancements on their site and Jason suggested an upgrade. They also discussed the possible downtime and finalized the process.

6

31
14mo