Ankur Gupta
09/18/2021, 7:40 PMschema = {
'name': 'content',
'fields': [
{
'name': 'client_id',
'type': 'int32',
'facet' : True
},
{
'name': 'title',
'type': 'string'
},
{
'name': 'url',
'type': 'string',
},
{
'name': 'description',
'type': 'string',
},
{
'name': 'image',
'type': 'string',
},
{
'name': 'last_crawled',
'type': 'string',
},
{
'name': 'summary',
'type': 'string'
},
{
'name': 'favicon',
'type': 'string'
},
{
'name': 'content_id',
'type': 'int32',
'facet' : True
}
]
}
please note facet is True
for content_id
and client_id
I need to get aggregate count of client_id + content_id combination.
So I wrote this query
search_parameters = {
'q' : '*',
'facet_by' : 'client_id,content_id',
'filter_by' : 'client_id:{}&&content_id:{}'.format(client_id, content_id),
'page': 1,
'per_page': 1,
}
which gives me
'facet_counts': [
{
'counts': [
{
'count': 49,
'highlighted': '1',
'value': '1'
}
],
'field_name': 'client_id',
'stats': {
'avg': 1.0,
'max': 1.0,
'min': 1.0,
'sum': 49.0
}
},
{
'counts': [
{
'count': 49,
'highlighted': '2',
'value': '2'
}
],
'field_name': 'content_id',
'stats': {
'avg': 2.0,
'max': 2.0,
'min': 2.0,
'sum': 98.0
}
}
],
'found': 49,
'hits': [
{
'document': {
'client_id': 1,
'content_id': 2,
'description': '',
'favicon': '',
'id': '99',
'image': '<https://www.glofox.com/wp-content/uploads/2021/04/The20Studio.png>',
'last_crawled': '2021-09-18 19:12:05.430002',
'summary': '',
'title': '12 Things Your Gym Website Needs in 2021 - Boutique Fitness and Gym Management Software - Glofox',
'url': '<https://www.glofox.com/blog/how-to-create-a-great-gym-website-right-now/>'
},
'highlights': [
],
'text_match': 16737280
}
],
'out_of': 102,
'page': 1,
'request_params': {
'collection_name': 'content',
'per_page': 1,
'q': '*'
},
'search_time_ms': 2
}
The
'found': 49,
is right for client_id 1 and content_id 1. So it looks all good to me against a small test dataset. Just want someone to spare 2-3 min and QA this. I am new to typesense and about to dump 27 GB worth of prod data into this, if I am missing something obvious I rather discover it now 😛 . Thanks.Kishore Nallan
09/19/2021, 6:49 AMI need to get aggregate count of client_id + content_id combination.Do you mean aggregate on client_id and content_id separately? Not sure what you mean by "combination". Do you want to treat a [client_id, content_id] as a composite key?
Ankur Gupta
09/19/2021, 6:07 PM