#community-help

Resolving an issue with 'auto' type in 'print_types'

TLDR Fulvio encountered a problem with 'auto' type for 'print_types'. Jason assisted in identifying a workaround, suggesting prefixing attribute names and using 'auto' type to resolve data typing issues.

Powered by Struct AI
+11
22
26mo
Solved
Join the chat
Jul 27, 2021 (26 months ago)
Fulvio
Photo of md5-16d994e060b67ac78785fe582156de68
Fulvio
06:09 PM
status: 400 response: {“message”: “Cannot use type auto for print_types. It can be used only for a field name containing .*“}
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:10 PM
This is expected. The idea being that is that if you know a field name already, then you probably already know its type as well.
06:10
Jason
06:10 PM
The goal of auto was to help automatically resolve data types for fields with regex in them
06:11
Jason
06:11 PM
Do you have a case where the type of print_types is not known upfront?
Fulvio
Photo of md5-16d994e060b67ac78785fe582156de68
Fulvio
06:11 PM
Yep,
06:11
Fulvio
06:11 PM
In this case its a json payload.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:12 PM
Do you need to search inside the json fields, or do you just want to store and retrieve it?
Fulvio
Photo of md5-16d994e060b67ac78785fe582156de68
Fulvio
06:12 PM
but there is cases that i dont know.. because i fetch it from an attribute list and there is no field type
06:12
Fulvio
06:12 PM
in this case just store..
06:12
Fulvio
06:12 PM
but there is others i need to search and they are facets
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:12 PM
If you just need to store and retrieve, you actually need not even mention it in the schema
06:13
Jason
06:13 PM
You only need to list fields that you want to search/facet/filter in the schema
06:14
Jason
06:14 PM
> but there is others i need to search and they are facets
Could you give me an example use case for this?
Fulvio
Photo of md5-16d994e060b67ac78785fe582156de68
Fulvio
06:14 PM
A have a table in the bd with the list of attributes that the products can have..
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:15 PM
So each Typesense document is a product record, and the set of fields are dynamic for each product, based on the product type?
Fulvio
Photo of md5-16d994e060b67ac78785fe582156de68
Fulvio
06:16 PM
yep..
06:16
Fulvio
06:16 PM
But there is like 100 types 😄
06:16
Fulvio
06:16 PM
its an old db structure
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:17 PM
I'd recommend defining a field like this in the schema:

{ name: "attribute_.*", type: "auto", optional: true }
06:17
Jason
06:17 PM
then when you add the product document to the collection, prefix all the attribute names with attribute_
Fulvio
Photo of md5-16d994e060b67ac78785fe582156de68
Fulvio
06:18 PM
humm ok cool.. thanks…
06:18
Fulvio
06:18 PM
will try 😄
+11