Manav Kothari
11/11/2024, 6:13 AM### Run Typesense via Docker ########################################
export TYPESENSE_API_KEY=xyz
mkdir "$(pwd)"/typesense-data
docker run -p 8108:8108 \
-v"$(pwd)"/typesense-data:/data typesense/typesense:27.1 \
--data-dir /data \
--api-key=$TYPESENSE_API_KEY \
--enable-cors
### Reproduction Steps ###############################################
export TYPESENSE_API_KEY=xyz
curl "<http://localhost:8108/debug>" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}"
curl "<http://localhost:8108/collections>" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "companies",
"fields": [
{"name": "company_name", "type": "string" },
{"name": "num_employees", "type": "int32" },
{"name": "country", "type": "string", "facet": true }
],
"default_sorting_field": "num_employees"
}'
curl "<http://localhost:8108/collections/companies/documents/import?action=create>" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{"id": "124","company_name": "Stark Industries","num_employees": 5215,"country": "USA"}
{"id": "125","company_name": "Acme Corp 1","num_employees": 2133,"country": "CA"}
{"id": "126","company_name": "Acme Corp 2","num_employees": 2133,"country": "USA"}
{"id": "127","company_name": "Acme Corp 3","num_employees": 2133,"country": "INDIA"}
{"id": "128","company_name": "Stark Industries 2","num_employees": 5215,"country": "USA"}
{"id": "129","company_name": "Acme Corp 4","num_employees": 2133,"country": "CA"}
{"id": "120","company_name": "Acme Corp 5","num_employees": 2133,"country": "USA"}
{"id": "122","company_name": "Acme Corp 6","num_employees": 2133,"country": "INDIA"}'
curl "<http://localhost:8108/collections>" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "development",
"fields": [
{
"index": true,
"name": "workspace_id",
"type": "string"
},
{
"name": "user_id",
"type": "string"
},
{
"name": "company_id",
"reference": "companies.id",
"optional": true,
"index": true,
"type": "string"
},
{
"index": true,
"name": "stage",
"type": "string"
}
]
}'
curl "<http://localhost:8108/collections/development/documents/import?action=create>" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{"workspace_id": "a","user_id": "test","company_id": "124","stage": "saved"}
'
curl "<http://localhost:8108/multi_search>" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"searches": [
{
"collection": "companies",
"q": "*",
"filter_by":"(country:[`India`] && company_name:[`Acme Corp 6`]) || $development(workspace_id: 'a')"
}
]
}'
### Documentation ######################################################################################
# Visit the API reference section: <https://typesense.org/docs/27.1/api/collections.html>
# Click on the "Shell" tab under each API resource's docs, to get shell commands for other API endpoints