#community-help

Troubleshooting Typesense 400 Error with Null Fields

TLDR sonu was encountering a 400 error due to null fields during Typesense indexing. Jason suggested upgrading to a recent version, removing null fields, and marking potentially null fields as optional: true. gab shared a similar issue and workaround.

Powered by Struct AI
26
26mo
Solved
Join the chat
Jul 09, 2021 (26 months ago)
sonu
Photo of md5-6ade4a341436f96c87480052a1584bf3
sonu
06:07 PM
i'm getting code 400 error from typesense while indexing ...because some of my fields some time returns null ....what should i do, i set them as string in typesense schema but some of are saved as null in db
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:07 PM
We addressed this in a recent RC build. What version of Typesense are you running?
sonu
Photo of md5-6ade4a341436f96c87480052a1584bf3
sonu
06:10 PM
0.12.1
06:10
sonu
06:10 PM
should i upgrade
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:12 PM
Oh yes! 0.21.0.rc24 is the latest version
06:13
Jason
06:13 PM
The workaround for previous versions is to remove null fields from the document fully
sonu
Photo of md5-6ade4a341436f96c87480052a1584bf3
sonu
06:35 PM
btw ..sorry but how do i install that rc version .....i tried this method i found ....didn't work 😅
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:40 PM
Oh I was talking about Typesense Server version. Those instructions are for typesense-js
06:41
Jason
06:41 PM
Are you self hosting or using Typesense Cloud?
sonu
Photo of md5-6ade4a341436f96c87480052a1584bf3
sonu
06:41 PM
i'm using docker ...as in self hosting
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:42 PM
What's the docker command you're using to start Typesense?
sonu
Photo of md5-6ade4a341436f96c87480052a1584bf3
sonu
06:43 PM
docker run -i -p 8108:8108 -v /tmp/typesense-data/:/data -v /tmp/typesense-logs/:/logs  typesense/typesense:0.20.0 --data-dir /data  --log-dir /logs  --api-key=xyz --listen-port 8108 --enable-cors
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:44 PM
> typesense/typesense:0.20.0
You want to change that to typesense/typesense:0.21.0.rc24
06:44
Jason
06:44 PM
and re-run that command
sonu
Photo of md5-6ade4a341436f96c87480052a1584bf3
sonu
06:45 PM
ohh ....silly me
07:17
sonu
07:17 PM
its the same even after using 0.21.0.rc24 ...gives 400error and says error: 'Field skill must be a string.',
07:18
sonu
07:18 PM
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
07:21 PM
Could you share the schema and a sample document (JSON) that failed?
sonu
Photo of md5-6ade4a341436f96c87480052a1584bf3
sonu
07:27 PM
yes sure
07:28
sonu
07:28 PM
rating is null for this one ....but in schema i set it as int32
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
08:01 PM
I have the same issue. For now I have replaced my null values with undefined values. Also I have set as optional the field that can be nullish.
sonu
Photo of md5-6ade4a341436f96c87480052a1584bf3
sonu
08:07 PM
gab so set as undefined and optional ...does it affect your searching with typesense
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:07 PM
Oh you want to set fields that can be null as optional: true in the collection schema
sonu
Photo of md5-6ade4a341436f96c87480052a1584bf3
sonu
08:08 PM
ohh thanks Jason
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
08:32 PM
I mean if I try to index a null value with a field that has (optional:true) it will give me an error 400. Is that intended behavior?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:12 PM
That used to be the case with v0.20.0. We've fixed that case in the most recent RC build: v0.21.0.rc24