Skip to content

Instantly share code, notes, and snippets.

@alexkappa
Forked from jasonbosco/typesense-repro-steps.sh
Last active August 7, 2025 12:24
Show Gist options
  • Select an option

  • Save alexkappa/c649f559ba9b60cd9713ec3177f8004e to your computer and use it in GitHub Desktop.

Select an option

Save alexkappa/c649f559ba9b60cd9713ec3177f8004e to your computer and use it in GitHub Desktop.
Quick set of curl commands to help reproduce any issues with Typesense
### Run Typesense via Docker ########################################
set -x
export TYPESENSE_API_KEY=xyz
export TYPESENSE_HOST=http://localhost:8108
docker stop typesense-repro 2>/dev/null
docker rm typesense-repro 2>/dev/null
rm -rf "$(pwd)"/typesense-data-dir-repro
mkdir "$(pwd)"/typesense-data-dir-repro
# Wait for Typesense to be ready
docker run -d -p 8108:8108 --name typesense-repro \
-v"$(pwd)"/typesense-data-dir-repro:/data \
typesense/typesense:29.0 \
--data-dir /data \
--api-key=$TYPESENSE_API_KEY \
--enable-cors
# Wait till typesense is ready.
until curl -s -o /dev/null -w "%{http_code}" "$TYPESENSE_HOST/health" -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" | grep -q "200"; do
sleep 2
done
curl -s "$TYPESENSE_HOST/debug" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" | jq
curl -s "$TYPESENSE_HOST/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{
"name": "users",
"fields": [
{"name": "email", "type": "string", "facet": true, "optional": true, "token_separators": [ ".", "-", "_", "@"]}
],
"token_separators": [".", "-", "_"]
}' | jq
curl -s "$TYPESENSE_HOST/collections/users/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{"id":"124", "email":"bob.saget@example.org"}
{"id":"125", "email":"zack.morris@example.com"}
{"id":"125", "email":"tony.danza@example.net"}' | jq
curl -s "$TYPESENSE_HOST/multi_search" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '
{
"searches": [
{
"collection": "users",
"q": "example",
"query_by": "email"
}
]
}' | jq
docker stop typesense-repro
docker rm typesense-repro
### Documentation ######################################################################################
# Visit the API reference section: https://typesense.org/docs/28.0/api/collections.html
# Click on the "Shell" tab under each API resource's docs, to get shell commands for other API endpoints
@alexkappa
Copy link
Author

Output:

{
  "results": [
    {
      "facet_counts": [],
      "found": 2,
      "hits": [
        {
          "document": {
            "email": "zack.morris@example.com",
            "id": "125"
          },
          "highlight": {
            "email": {
              "matched_tokens": [
                "com"
              ],
              "snippet": "zack.morris@example.<mark>com</mark>"
            }
          },
          "highlights": [
            {
              "field": "email",
              "matched_tokens": [
                "com"
              ],
              "snippet": "zack.morris@example.<mark>com</mark>"
            }
          ],
          "text_match": 578730123365187705,
          "text_match_info": {
            "best_field_score": "1108091338752",
            "best_field_weight": 15,
            "fields_matched": 1,
            "num_tokens_dropped": 0,
            "score": "578730123365187705",
            "tokens_matched": 1,
            "typo_prefix_score": 0
          }
        },
        {
          "document": {
            "email": "bob.saget@example.org",
            "id": "124"
          },
          "highlight": {
            "email": {
              "matched_tokens": [
                "org"
              ],
              "snippet": "bob.saget@example.<mark>org</mark>"
            }
          },
          "highlights": [
            {
              "field": "email",
              "matched_tokens": [
                "org"
              ],
              "snippet": "bob.saget@example.<mark>org</mark>"
            }
          ],
          "text_match": 578730123365187705,
          "text_match_info": {
            "best_field_score": "1108091338752",
            "best_field_weight": 15,
            "fields_matched": 1,
            "num_tokens_dropped": 0,
            "score": "578730123365187705",
            "tokens_matched": 1,
            "typo_prefix_score": 0
          }
        }
      ],
      "out_of": 2,
      "page": 1,
      "request_params": {
        "collection_name": "users",
        "first_q": "example",
        "per_page": 10,
        "q": "example"
      },
      "search_cutoff": false,
      "search_time_ms": 1
    }
  ]
}

@alexkappa
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment