#community-help

Creating Unique ID from URL Field in Typesense DB

TLDR andy wanted to make the 'url' field the 'id' in typesense DB. Kishore Nallan advised that the 'id' field is always the ID by convention, but andy could duplicate the content as 'id', rename it, or use the 'url' field as 'id'.

Powered by Struct AI

1

6
10mo
Solved
Join the chat
Dec 13, 2022 (10 months ago)
andy
Photo of md5-8f2bc7de8159dde57045bf51154aed5b
andy
10:43 AM
hi all, i am wondering if i can create an id from a field in the json import, I have a unique field called url which is in the form /keyword or /node/123 and would like to make that also the id for the typesense db. Can i set this in the schema, or should i duplicate it in the json import files? i am going to play with updating the data today to see how that works, and think it would be better to set my own id, rather than use the default one created when i import without an id field.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:49 AM
There's no way to make a particular field the id field. By convention the field named id is always the ID. If you want the url field to be the identifier, duplicate the content as id .
andy
Photo of md5-8f2bc7de8159dde57045bf51154aed5b
andy
10:50 AM
or i could just rename the url field as id and use that :)
10:50
andy
10:50 AM
thanks, i am really enjoying working with typesense, it is great

1

Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:51 AM
Yes you can rename it. But the id is a special field so you can't search on it.
andy
Photo of md5-8f2bc7de8159dde57045bf51154aed5b
andy
10:51 AM
oh i, see, i may as well duplicate it then