Peter Petvus
08/06/2024, 1:51 PMservices:
typesense:
image: typesense/typesense:26.0
container_name: test-typesense
restart: on-failure
volumes:
- ./typesense-data-dir:/data
ports:
- 8108:8108
command: '--data-dir /data --api-key=xyz --enable-cors --cors-domains=<http://localhost:8188> --enable-search-analytics=true --analytics-dir=/data/analytics --analytics-flush-interval=60'
typesense_dashboard:
image: <http://ghcr.io/bfritscher/typesense-dashboard:latest|ghcr.io/bfritscher/typesense-dashboard:latest>
container_name: test-typesense_dashboard
restart: on-failure
volumes:
- ./typesense-dashboard/config.json:/srv/config.json
ports:
- 8188:80
## create collection
curl "<http://localhost:8108/collections>" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
-d '{
"name": "product_variants",
"fields": [
{"name": "name", "type": "string" },
{"name": "popularity", "type": "int32" }
],
"default_sorting_field": "popularity"
}'
## insert document
curl "<http://localhost:8108/collections/product_variants/documents>" -X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
-d '{
"id": "1",
"name": "First test product",
"popularity": 0
}'
## create rule
curl -k "<http://localhost:8108/analytics/rules>" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz" \
-d '{
"name": "product_variants_popularity",
"type": "counter",
"params": {
"source": {
"collections": ["product_variants"],
"events": [
{"type": "click", "weight": 1, "name": "product_variants_click_event"}
]
},
"destination": {
"collection": "product_variants",
"counter_field": "popularity"
}
}
}'
## restart docker containers
docker-compose down && docker-compose up -d
## check if rule is still present
curl -k "<http://localhost:8108/analytics/rules>" \
-X GET \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: xyz"