如何在typesense中存储具有键值的数组
How to store array with key value in typesense
我是排字新手,
我在 typesense 中为 geoloc 创建了一个模式。
架构
curl "http://localhost:8108/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
-d '{
"name": "demo",
"fields": [
{"name": "name", "type": "string" },
{"name": "city", "type": "string" },
{"name": "country", "type": "string" },
{"name": "iata_code", "type": "string" },
{"name": "_geoloc", "type": "string[]" , "facet": true },
{"name": "links_count", "type": "int32" },
{"name": "objectID", "type": "string" }
]
}'
我尝试用
存储
curl "http://localhost:8108/collections/airports4/documents/import" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
-d '
{"name": "Kalemie","city": "Kalemie","country": "Congo (Kinshasa)","iata_code": "FMI","_geoloc": { "lat" : -5.875556 , "long" : 29.25 },"links_count":1,"objectID": "1040"}'
但是它returns一个错误
{"code":400,"document":"{","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - unexpected end of input; expected string literal","success":false}
{"code":400,"document":"\t\"name\": \"Kalemie\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"city\": \"Kalemie\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"country\": \""Congo (Kinshasa)\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 11: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"iata_code\": \"FMI\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"_geoloc\" : [{\"lat\":-5.875556 , \"lng\": 29.25 }],","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 12: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"links_count\": 1,","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 15: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"objectID\": \"1040\"","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 12: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"}","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal","success":false}
我不知道如何用经纬度存储 _geoloc。
您必须使用 geopoint
.
类型的字段
这是文档中的示例:https://typesense.org/docs/0.21.0/api/documents.html#geosearch
我是排字新手, 我在 typesense 中为 geoloc 创建了一个模式。
架构
curl "http://localhost:8108/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
-d '{
"name": "demo",
"fields": [
{"name": "name", "type": "string" },
{"name": "city", "type": "string" },
{"name": "country", "type": "string" },
{"name": "iata_code", "type": "string" },
{"name": "_geoloc", "type": "string[]" , "facet": true },
{"name": "links_count", "type": "int32" },
{"name": "objectID", "type": "string" }
]
}'
我尝试用
存储curl "http://localhost:8108/collections/airports4/documents/import" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
-d '
{"name": "Kalemie","city": "Kalemie","country": "Congo (Kinshasa)","iata_code": "FMI","_geoloc": { "lat" : -5.875556 , "long" : 29.25 },"links_count":1,"objectID": "1040"}'
但是它returns一个错误
{"code":400,"document":"{","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - unexpected end of input; expected string literal","success":false}
{"code":400,"document":"\t\"name\": \"Kalemie\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"city\": \"Kalemie\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"country\": \""Congo (Kinshasa)\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 11: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"iata_code\": \"FMI\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"_geoloc\" : [{\"lat\":-5.875556 , \"lng\": 29.25 }],","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 12: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"links_count\": 1,","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 15: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"\t\"objectID\": \"1040\"","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 12: syntax error while parsing value - unexpected ':'; expected end of input","success":false}
{"code":400,"document":"}","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected '}'; expected '[', '{', or a literal","success":false}
我不知道如何用经纬度存储 _geoloc。
您必须使用 geopoint
.
这是文档中的示例:https://typesense.org/docs/0.21.0/api/documents.html#geosearch