#community-help

Resolving Error with Hash Objects in Typesense

TLDR V had trouble with hash object fields not showing in a Typesense schema. Kishore Nallan advised enabling nested fields in the schema creation code.

Powered by Struct AI
Dec 02, 2022 (13 months ago)
V
Photo of md5-9731f28d447ea3926a50dd0fbd44c965
V
12:27 PM
Hey guys
i facing issue with hash object
hash object is showing in the documents but not showing field name in the schema so when i performing search it throw an error like data field not exist in the schema
what i am doing wrong?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:35 PM
Did you add the field in the schema when you created the collection?
V
Photo of md5-9731f28d447ea3926a50dd0fbd44c965
V
12:44 PM
No, I follow auto schema detection.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:45 PM
Please post a code snippet that showcases the problem.
V
Photo of md5-9731f28d447ea3926a50dd0fbd44c965
V
01:11 PM
Typesense::Base.new.client.collections['listings'].documents.search({
      q: query, query_by:'address.name',
      filter_by: [].join(' && ')
    })

when i hit above query it give me an error as show in image
01:12
V
01:12 PM
but it is present in the documents
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:13 PM
Is address an object field? If so you should enable nested field at the collection level with this option:

"enable_nested_fields": true
V
Photo of md5-9731f28d447ea3926a50dd0fbd44c965
V
01:17 PM
i create auto schema
so when i insert data in the typesense
it does not created new field with hash object (address)
01:20
V
01:20 PM
means i am not getting the field name in the schema but it showing in the documents
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:26 PM
Can you post the code that creates the schema?
V
Photo of md5-9731f28d447ea3926a50dd0fbd44c965
V
01:29 PM
address_schema =
      {
        'name' => 'address',
        'fields' => [
          { 'name' => '.*', 'type' => 'auto' }

        ]
      }
    Typesense::Base.new.client.collections.create(address_schema)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:30 PM
Yeah, so it must be like this:

{
        'name' => 'address',
        'enable_nested_fields' => True,
        'fields' => [
          { 'name' => '.*', 'type' => 'auto' }

        ]
      }
01:30
Kishore Nallan
01:30 PM
If you don't provide enable_nested_fields -> the object field won't be searchable.
V
Photo of md5-9731f28d447ea3926a50dd0fbd44c965
V
01:34 PM
Okay Thanks
let me try.

Typesense

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

Indexed 3015 threads (79% resolved)

Join Our Community