Hey All , I am bit struggling with typesense analy...
# community-help
z
Hey All , I am bit struggling with typesense analytics. I tried to get the most searched product but somehow my “top_queries” collection is empty. I don’t get any error but still my “top_queries” remains empty.Below is the docker file I used to run my typesense server. Used this for reference : https://gist.github.com/jasonbosco/0c49916fc2e7a54f30d961aac111cf4a Used this compose file to run my server :
version: '3.4'
services:
typesense:
image: typesense/typesense:0.25.0.rc62
restart: on-failure
ports:
- "8108:8108"
volumes:
- ./typesense-data:/data
command: '--data-dir /data --api-key=xyz --enable-cors --enable-search-analytics=true --analytics-flush-interval=60'
TIA
k
Can you post the schema of the top_queries collection?
z
yes sure
Copy code
curl -k "<http://localhost:8108/collections>" -X POST -H "Content-Type: application/json" \
      -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '{
        "name": "top_queries",
        "fields": [
          {"name": "q", "type": "string" },
          {"name": "count", "type": "int32" }
        ]
      }'
used this req to create the schema
I have actually simply referred to this article. and just changed my source collection https://gist.github.com/jasonbosco/0c49916fc2e7a54f30d961aac111cf4a
this.typeSenseClient.collections( collectionName ).retrieve();
this is how i am retrieving the collection . I am using typesense client for node/nest js
@Kishore Nallan could you please help , what i am doing wrong?
k
Sorry I'm tied up with a couple of other ongoing issues. Someone will investigate and get back to you soon.
j
Could you also do a
GET /analytics/rules
and post the output?
z
@Jason Bosco {“rules”[{“name”“top_queries”,“params”{“destination”{“collection”“top queries”},“limit”1000,“source”{“collections”[“products”]}},“type”:“popular_queries”}]}
@Kishore Nallan sure . sorry for disturbing man . Kudos for building a great product and community 🙌
k
No worries!
🙌 1
j
Could you post the schema of your source collection as well and the search query you’re sending it? (Could you post it in a code block in Slack - three backticks, otherwise Slack replaces quotes and makes it hard to parse through)
z
yes @Jason Bosco
Product Schema:
const productSchema: CollectionCreateSchema = {
name: this.collectionName,
fields: [
{ name: "id", type: "string" },
{ name: "name", type: "string" },
{ name: "description", type: "string" },
{ name: "category", type: "string[]" },
{ name: "brand", type: "string" },
{ name: "company", type: "string" },
{ name: "status", type: "bool" },
{ name: "isHidden", type: "bool" }
]
};
await this.searchService.createCollection( productSchema );
Search Query:-
const searchParams: SearchParams = {
enable_overrides: true,
filter_by: "status:=true && isHidden:=false",
q: query,
query_by: "name,description,category,brand,company"
};
const product = await this.searchService.searchFromCollection( this.collectionName, searchParams );
j
It’s hard to the debug with the variables in the code… Could you come up with a set of curl commands like this that replicates the issue end-to-end, so I can try and replicate it on my end?
z
sure
Steps to repro
j
Step 6 Now search on Product collection (Repeat Step 3)
Repeated the step 3 time to check the count of query “garam” You’re waiting at least 60s after this step right? Because that’s what this parameter does:
analytics-flush-interval=60
Also on step 7, that only gets the collection schema of the top_queries collection. You want to do an export of the data in the collection to get all the search terms
z
yes i have waited 60 seconds but still its giving me 0 docs
curl -H "X-TYPESENSE-API-KEY: xyz" \
"<http://localhost:8108/collections/top_queries/documents/search>\
?q=*&query_by=q"
this req gives this result
{"facet_counts":[],"found":0,"hits":[],"out_of":0,"page":1,"request_params":{"collection_name":"top_queries","per_page":10,"q":"*"},"search_cutoff":false,"search_time_ms":3}
this request is also returning 0 docs
j
I was able to replicate the issue. Will take a look and keep you posted
🙌 1
z
Thankyou so much @Jason Bosco
k
@Zain Haider I've a fix for this in
0.25.0.rc66
-- can you please try that out?
z
@Kishore Nallan sure , I will update here after trying that
@Kishore Nallan its working for the repro doc . Thanks for the instant support 🙌
🙌 1
let me try it with js client too and update you here
n
Hey guys! I'm having a similar issue here where analytics collection isn't populating - I'm using Typesense Cloud and have the scheme pretty basic as depicted in the docs:
Copy code
"fields": [
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "q",
      "optional": false,
      "sort": false,
      "type": "string"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "count",
      "optional": false,
      "sort": true,
      "type": "int32"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "timestamp",
      "optional": true,
      "sort": true,
      "type": "int64"
    }
  ]
One of my main collections (I have 2) has a scheme like this - not sure if it matters:
Copy code
"fields": [
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": ".*",
      "optional": true,
      "sort": false,
      "type": "auto"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "category",
      "optional": true,
      "sort": false,
      "type": "object"
    },
    {
      "facet": false,
      "index": true,
      "infix": false,
      "locale": "",
      "name": "description",
      "optional": true,
      "sort": false,
      "type": "string"
    }
Appreciate the help!
j
We found another issue on Typesense Cloud with analytics. Could you upgrade to
0.25.2.rc1
and try again?
n
Hey Jason - thanks for replying. I'm using TS Cloud, I didn't realize we could upgrade instances on that. Can you guide me to how please
j
You want to open your Cluster dashboard -> Cluster configuration (on the side pane) -> Modify (button on top) and then you'll be able to change the Typesense Version (and other parameters if needed) and schedule a change for now or later
n
Got it thanks - will give that a try shortly
👍 1
That seems to have done the trick - thanks!
👍 1