Raz
10/19/2023, 3:23 PM{ "message": "Not Found"}
. I'm sure that the destination and source collections that I'm sending exist on the cloud. I'm sending popular_queries
for the name and type. can you help me to understand why I'm getting 404
, please? when do you return 404 for the POST url/analytics/rules
endpoint? Thanks.Raz
10/19/2023, 4:07 PMOn Typesense Cloud
We automatically set --enable-search-analytics=true and --analytics-flush-interval=300 (every 5 minutes) in Typesense Cloud (more context in the section above).
Raz
10/19/2023, 4:08 PMJason Bosco
10/19/2023, 4:21 PMJason Bosco
10/19/2023, 4:21 PMRaz
10/19/2023, 4:21 PMRaz
10/19/2023, 4:21 PMcurl -k "<https://313asdfasfa31241.typesense.net/analytics/rules/>" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: " \
-d '{
"name": "popular_queries",
"type": "popular_queries",
"params": {
"source": {
"collections": ["products_v6"]
},
"destination": {
"collection": "products_analytics_v1"
},
"limit": 1000
}
}'
Jason Bosco
10/19/2023, 4:23 PM0.24.0
which doesn't have the analytics feature.
You want to upgrade to v0.25.2.rc6
(Cluster Configuration > Modify). Could you do that and try again?Jason Bosco
10/19/2023, 4:35 PMRaz
10/19/2023, 4:35 PMRaz
10/19/2023, 4:35 PMJason Bosco
10/19/2023, 4:36 PMRaz
10/19/2023, 4:36 PMRaz
10/19/2023, 4:36 PMRaz
10/19/2023, 4:45 PMError (Typesense::Error::HTTPStatus0Error)
. maybe it's something wrong with the ruby client. I'll create the rule manuallyJason Bosco
10/19/2023, 4:45 PMJason Bosco
10/19/2023, 4:45 PMRaz
10/19/2023, 4:53 PMRaz
10/19/2023, 4:53 PMRaz
10/19/2023, 5:05 PMRaz
10/19/2023, 5:05 PMJason Bosco
10/19/2023, 5:17 PMRaz
10/19/2023, 5:21 PMAndrew Denta
11/30/2023, 4:22 PMRaz
11/30/2023, 4:39 PMAndrew Denta
11/30/2023, 4:48 PMAndrew Denta
11/30/2023, 4:48 PMmodule Searchable
extend ActiveSupport::Concern
included do
after_save :reindex_after_save
after_destroy :destroy_indexed_document # No idea why this works, you'd think the fact that the record was deleted would prevent an after_destroy hook from knowing what the records id was but it seems to work!
end
# Immediately after we save a searchable, we want that record to be reindexed inline.
# If something goes wrong, log it and throw it in the reindexing queue
# The queue takes a little bit of time to go through, but after you save a record you want
# it to be updated immediately, so we do it inline.
def reindex_after_save
reindex_inline
rescue Typesense::Error => e
puts e
end
def collection_index
TypesenseClient.fetch.collections[self.class.index_name]
end
def indexed_document
collection_index.documents[id]
end
def indexed_document_json
indexed_document.retrieve
end
def destroy_indexed_document
indexed_document.delete
end
# actually reindexes the document
def reindex_inline
json = self.class.blueprint.render_as_json(self, view: :instantsearch)
collection_index.documents.upsert(json)
end
module ClassMethods
def index_name
name
end
def create_index
schema = formated_searchable_schema
TypesenseClient.fetch.collections.create(schema)
rescue Typesense::Error::ObjectAlreadyExists => e
puts e
end
def reindex_all_inline
json = blueprint.render_as_json(all, view: :instantsearch)
TypesenseClient.fetch.collections[index_name].documents.import(json, { action: 'upsert' })
end
def inspect_index
JSON(['[', TypesenseClient.fetch.collections[index_name].documents.export.gsub("\n", ','), ']'].join(''))
end
def destroy_index
TypesenseClient.fetch.collections[index_name].delete
end
def blueprint
blueprint_name = "#{name.demodulize.classify}Blueprint"
blueprint_name.constantize
end
private
def formated_searchable_schema
rv = searchable_schema_hash
rv['name'] = index_name if rv['name'].blank?
rv['fields'] = searchable_schema_hash['fields'].map do |searchable_schema_field|
searchable_schema_field['name'] = searchable_schema_field['name'].camelcase(:lower)
searchable_schema_field
end
rv['default_sorting_field'] = 'created_at'.camelcase(:lower) if rv['default_sorting_field'].blank?
rv
end
def searchable_schema_class
searchable_schema_name = "#{name.demodulize.classify}SearchableSchema"
searchable_schema_name.constantize
end
def searchable_schema_hash
searchable_schema_class.as_hash
end
end
end
Andrew Denta
11/30/2023, 4:49 PMJason Bosco
11/30/2023, 5:38 PM