Skip to content

Instantly share code, notes, and snippets.

@jasonbosco
Last active May 2, 2024 21:27
Show Gist options
  • Save jasonbosco/7c3432713216c378472f13e72246f46b to your computer and use it in GitHub Desktop.
Save jasonbosco/7c3432713216c378472f13e72246f46b to your computer and use it in GitHub Desktop.
export TYPESENSE_API_KEY=xyz
mkdir "$(pwd)"/typesense-data
docker run -p 8108:8108 \
-v"$(pwd)"/typesense-data:/data typesense/typesense:26.0 \
--data-dir /data \
--api-key=$TYPESENSE_API_KEY \
--enable-cors
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","num_employees": 2133,"country": "CA"}'
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": "stark",
"query_by": "company_name"
}
]
}'
# Click on the "Shell" tab under each API resource's docs, to get shell commands for other API endpoints:
# Eg: https://typesense.org/docs/26.0/api/collections.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment