Simon Defrenne
06/19/2024, 12:19 PM{
"created_at": 1718798058,
"default_sorting_field": "",
"enable_nested_fields": false,
"fields": [
{
"facet": true,
"index": true,
"infix": false,
"locale": "",
"name": "company",
"optional": false,
"sort": false,
"stem": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "name",
"optional": false,
"sort": false,
"stem": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "description",
"optional": false,
"sort": false,
"stem": false,
"type": "string"
},
{
"facet": true,
"index": true,
"infix": false,
"locale": "",
"name": "product_type",
"optional": false,
"sort": false,
"stem": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "last_update",
"optional": false,
"sort": true,
"stem": false,
"type": "string"
},
{
"facet": false,
"index": true,
"infix": false,
"locale": "",
"name": "popularity",
"optional": true,
"sort": true,
"stem": false,
"type": "int32"
}
],
"name": "products19JUNE",
"num_documents": 40,
"symbols_to_index": [],
"token_separators": []
}
Notice the last field, "popularity".
I have created an analytics rule to register various event:
{
"name": "products_popularity",
"params": {
"destination": {
"collection": "products",
"counter_field": "popularity"
},
"source": {
"collections": [
"products"
],
"events": [
{
"name": "products_click_event",
"type": "click",
"weight": 1
},
{
"name": "products_visit_event",
"type": "visit",
"weight": 2
},
{
"name": "products_conversion_event",
"type": "conversion",
"weight": 5
}
]
}
},
"type": "counter"
}
I attempt to send the following event:
"<http://localhost:8108/analytics/events>" -X POST -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
"type": "conversion",
"name": "products_purchase_event",
"data": {
"doc_id": "some-doc-id",
"user_id": "some-user-id"
}
}'
The first problem happens here: it requires me to create a 'q' field in the 'data' field, which is not mentioned in the documentation. "some-doc-id" and "some-user-id" are used as placeholders value, but should otherwise be correct in my code.
If I add that 'q' field, with whatever value, I get back an ok: true response, but the popularity of the relevant element is not increased, and I do not understand why. Can someone help me, please ?