#community-help

Querying Nested Fields in Array Using Filters

TLDR Todd asked about using wildcards for array style searches in a nested field. Jason responded that using filter_by: topLevelField.nestedField:=5 should work. Todd confirmed that the solution was effective.

Powered by Struct AI
+12
5
2mo
Solved
Join the chat
Jul 03, 2023 (2 months ago)
Todd
Photo of md5-cccf0b87668408fef09dd77e1948fced
Todd
08:22 PM
Hey all, the nested field stuff is looking great! However, I’m struggling to use them in filter conditions when nested in arrays. I was wondering if there was support for wildcards in array style searches, similar to a “some” check in SQL

For example, if I have this schema:

const schema: CollectionFieldSchema[] = [
  {
    name: 'topLevelField',
    type: 'object[]',
    facet: true,
  },
  {
    facet: true,
    name: 'topLevelField.nestedField',
    type: 'int32',
  },
];

And I have an entry with this shape:

{ topLevelField: [{ nestedField: 3 }, { nestedField: 5}]}

How can I filter that 5 is in the nestedField list?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:25 PM
> I was wondering if there was support for wildcards in array style searches, similar to a “some” check in SQL
Typesense doesn’t support wild-cards in filter values

> How can I filter that 5 is in the nestedField list?
filter_by: topLevelField.nestedField:=5

should work…
08:25
Jason
08:25 PM
If that doesn’t work, could you replicate the issue using this snippet and some sample data?
Todd
Photo of md5-cccf0b87668408fef09dd77e1948fced
Todd
08:26 PM
Jason - Thanks as always for the quick turnaround, and if I hit any issues trying that I’ll follow the template. Thank you sir!
+11
08:41
Todd
08:41 PM
Jason - That syntax worked perfectly. Thank you!
+11