Sudip Parajuli
12/01/2024, 2:19 AMhotels_new
with over around 173000 data. and the search is perfectly working fine but since I am trying to create search suggestions. So, I run the following and the rules and the hotels_new queries are perfectly created without any error. I checked the queries it has initially 0 number of documents. The issue currently is when I do search on the hotels_new the hotels_new_queries isn't being updated. I have a Lightsail server hosted with the following configurations
Typesense Setup
hotels_new_queries = {
"name": "hotels_new_queries",
"fields": [
{"name": "q", "type": "string"},
{"name": "count", "type": "int64"}
]
}
client.collections.create(hotels_new_queries)
rule_name = 'hotels_new_queries_aggregation'
rule_configuration = {
"type": "popular_queries",
"params": {
"source": {
"collections": ["hotels_new"]
},
"destination": {
"collection": "hotels_new_queries"
},
"expand_query": False,
"limit": 1000
}
}
print(client.analytics.rules.upsert(rule_name, rule_configuration))
LightSail typesense.ini configuration
; Typesense Configuration
[server]
api-address = 0.0.0.0
api-port = 8108
data-dir = /var/lib/typesense
api-key = api_key_working_fine
log-dir = /var/log/typesense
enable-search-analytics = true
analytics-dir = /var/lib/typesense/analytics
analytics-flush-interval = 60
Also I checked the logs, everything seems fine and there is nothing unusual. Along with I also checked the /var/lib/typesense, all the files and permissions are same. I also checked after flush interval but nothing, the number of documents is 0.
What can I try next?Kishore Nallan
12/02/2024, 3:37 AMSudip Parajuli
12/03/2024, 2:36 AMKishore Nallan
12/03/2024, 4:11 AMSudip Parajuli
12/04/2024, 12:01 PMKishore Nallan
12/04/2024, 5:01 PMSudip Parajuli
12/06/2024, 11:51 AMdocker run -d --name typesense -p 8108:8108 -v $(pwd)/typesense-data:/data -v $(pwd)/typesense-analytics:/analytics -e TYPESENSE_API_KEY=abcd -e TYPESENSE_DATA_DIR=/data -e TYPESENSE_ENABLE_SEARCH_ANALYTICS=true -e TYPESENSE_ANALYTICS_DIR=/analytics -e TYPESENSE_ANALYTICS_FLUSH_INTERVAL=60 typesense/typesense:27.1
this was the docker command i run and this is the file i am testing can you please review am i missing something from typesense import Client
import time
import json
# Setup client
client = Client({
'nodes': [{
'host': 'localhost',
'port': '8108',
'protocol': 'http'
}],
'api_key': 'abcd',
'connection_timeout_seconds': 2
})
# Create books collection
try:
books_schema = {
"name": "books",
"fields": [
{"name": "title", "type": "string"},
{"name": "authors", "type": "string[]", "facet": True},
{"name": "publication_year", "type": "int32", "facet": True},
{"name": "ratings_count", "type": "int32"},
{"name": "average_rating", "type": "float"},
{"name": "image_url", "type": "string"}
],
"default_sorting_field": "ratings_count"
}
client.collections.create(books_schema)
except Exception as e:
print(f"Books collection warning: {e}")
# Add sample books
sample_books = [
{
'id': '1',
'authors': ['Suzanne Collins'],
'average_rating': 4.34,
'publication_year': 2008,
'title': 'The Hunger Games',
'image_url': 'https://images.gr-assets.com/books/1447303603m/2767052.jpg▾
https://example.com/cleancode.jpg▾
https://example.com/javascript.jpg▾
Sudip Parajuli
12/06/2024, 11:52 AMpython test_locally.py
Books collection warning: [Errno 409] A collection with name books
already exists.
Error adding book 1: [Errno 409] A document with id 1 already exists.
Error adding book 2: [Errno 409] A document with id 2 already exists.
Error adding book 3: [Errno 409] A document with id 3 already exists.
Queries collection warning: [Errno 409] A collection with name books_queries
already exists.
Analytics rule created: {'name': 'books_queries_aggregation', 'params': {'destination': {'collection': 'books_queries'}, 'limit': 1000, 'source': {'collections': ['books']}}, 'type': 'popular_queries'}
Retrieved rule: {'name': 'books_queries_aggregation', 'params': {'destination': {'collection': 'books_queries'}, 'expand_query': False, 'limit': 1000, 'source': {'collections': ['books']}}, 'type': 'popular_queries'}
Performing test searches...
Searched for 'Suzanne': 1 results
Searched for 'javascript': 1 results
Searched for 'Suzanne': 1 results
Searched for 'programming': 1 results
Searched for 'coding': 0 results
Waiting for analytics flush (120 seconds)...
Checking analytics collection...
Analytics Results: {'facet_counts': [], 'found': 0, 'hits': [], 'out_of': 0, 'page': 1, 'request_params': {'collection_name': 'books_queries', 'first_q': '*', 'per_page': 10, 'q': '*'}, 'search_cutoff': False, 'search_time_ms': 0}Kishore Nallan
12/12/2024, 9:48 AMtrue
must be in CAPS
Instead of
TYPESENSE_ENABLE_SEARCH_ANALYTICS=true
It should be
TYPESENSE_ENABLE_SEARCH_ANALYTICS=TRUE
We have fixed this in recent builds, but making the above change should work in 27.1Sudip Parajuli
12/12/2024, 11:23 AMKishore Nallan
12/12/2024, 11:28 AM