Slackbot
09/05/2023, 3:52 PMJason Bosco
09/05/2023, 4:58 PMVamshi Aruru
09/06/2023, 3:37 AMexport TYPESENSE_API_KEY=dummyAdminKeyToBeChanged
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": "product_variants",
"fields": [
{"name": "discountPercentage", "type": "float", "facet": true },
{"name": "productSlug", "type": "string", "facet": true },
{"name": "variantID", "type": "int32"}
]
}'
curl "http://localhost:8108/collections/product_variants/documents/import?action=create" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H "Content-Type: text/plain" \
-X POST \
-d '{"id": "124","discountPercentage": 10,"productSlug": "first","variantID": 1}
{"id": "125","discountPercentage": 20,"productSlug": "first","variantID": 2}
{"id": "126","discountPercentage": 30,"productSlug": "second","variantID": 3}
{"id": "127","discountPercentage": 25,"productSlug": "second","variantID": 4}
{"id": "128","discountPercentage": 60,"productSlug": "third","variantID": 5}
{"id": "129","discountPercentage": 70,"productSlug": "third","variantID": 6}'
# without group_by
curl --location --globoff 'http://localhost:8108/collections/product_variants/documents/search?q=*&query_by=productSlug&per_page=0&facet_by=discountPercentage(average%3A[0%2C30]%2Cgood%3A[30%2C70]%2Cgreat%3A[70%2C100])' \
--header "x-typesense-api-key: ${TYPESENSE_API_KEY}"
# with group_by
curl --location --globoff 'http://localhost:8108/collections/product_variants/documents/search?q=*&query_by=productSlug&per_page=0&group_by=productSlug&facet_by=discountPercentage(average%3A[0%2C30]%2Cgood%3A[30%2C70]%2Cgreat%3A[70%2C100])' \
--header "x-typesense-api-key: ${TYPESENSE_API_KEY}"Vamshi Aruru
09/06/2023, 3:38 AMcurl --location --globoff 'http://localhost:8108/collections/product_variants/documents/search?q=*&query_by=productSlug&per_page=0&facet_by=discountPercentage(average%3A[0%2C30]%2Cgood%3A[30%2C70]%2Cgreat%3A[70%2C100])' \
--header "x-typesense-api-key: ${TYPESENSE_API_KEY}"
# with group_by
curl --location --globoff 'http://localhost:8108/collections/product_variants/documents/search?q=*&query_by=productSlug&per_page=0&group_by=productSlug&facet_by=discountPercentage(average%3A[0%2C30]%2Cgood%3A[30%2C70]%2Cgreat%3A[70%2C100])' \
--header "x-typesense-api-key: ${TYPESENSE_API_KEY}"
{"facet_counts":[{"counts":[{"count":4,"highlighted":"","value":"average"},{"count":2,"highlighted":"","value":"good"}],"field_name":"discountPercentage","sampled":false,"stats":{"avg":35.833333333333336,"max":70.0,"min":10.0,"sum":215.0,"total_values":2}}],"found":6,"hits":[],"out_of":6,"page":1,"request_params":{"collection_name":"product_variants","per_page":0,"q":"*"},"search_cutoff":false,"search_time_ms":0}{"facet_counts":[{"counts":[{"count":0,"highlighted":"","value":"good"},{"count":0,"highlighted":"","value":"average"}],"field_name":"discountPercentage","sampled":false,"stats":{"avg":35.833333333333336,"max":70.0,"min":10.0,"sum":215.0,"total_values":2}}],"found":3,"found_docs":6,"grouped_hits":[],"out_of":6,"page":1,"request_params":{"collection_name":"product_variants","per_page":0,"q":"*"},"search_cutoff":false,"search_time_ms":0}%
Note how stats is same but the facet_counts array is different in two resultsKishore Nallan
09/06/2023, 7:04 AMVamshi Aruru
09/06/2023, 7:08 AMKishore Nallan
09/06/2023, 7:13 AM