Ajay Thakur
12/18/2024, 6:02 PMJason Bosco
12/18/2024, 7:58 PMAjay Thakur
12/19/2024, 6:11 AMAjay Thakur
12/19/2024, 6:12 AMAjay Thakur
12/19/2024, 5:57 PMJason Bosco
12/19/2024, 8:55 PMrange_index: true
to the age
field in the collection schema, since you're using it with the >
and <
operator. This will improve performance of that operation.
I'd also recommend using the range operator. So instead of age:>=18 && age:<=80
, you want to change that to age:[18..80]
.
The other heavy operation is the geo search on a 1.6 million kilometer radius geoLocation:(30.7046486, 76.71787259999999, 1609344.0 km)
. Any reason you have such a large area? For context, the earth's circumference itself is only 40K kilometers. If you reduce that value to a smaller number, then the query should speed upAjay Thakur
12/20/2024, 5:17 AMAjay Thakur
01/10/2025, 11:00 AMJason Bosco
01/10/2025, 4:47 PMJason Bosco
01/10/2025, 4:47 PMAjay Thakur
01/24/2025, 11:10 AMJason Bosco
01/24/2025, 7:51 PMAjay Thakur
01/30/2025, 7:38 PMAjay Thakur
01/30/2025, 7:38 PMJason Bosco
01/31/2025, 12:26 AMgeoLocation:(12.9715987, 77.5945627, 6437.36 km)
The area of a circle with a diameter of 6437.36kms is like 13 times the area of the entire United States. Such a large area of geosearch is bound to be slowJason Bosco
01/31/2025, 12:26 AMAjay Thakur
01/31/2025, 4:13 AMAjay Thakur
02/03/2025, 11:27 AMJason Bosco
02/03/2025, 3:21 PMJason Bosco
02/03/2025, 3:22 PMAjay Thakur
02/03/2025, 5:20 PMAjay Thakur
02/03/2025, 5:40 PMJason Bosco
02/03/2025, 9:54 PMcurl -s '<https://71vf8usilhjkac6gp-1.a1.typesense.net/multi_search>' \
-X POST \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"searches": [
{
"collection": "users",
"q": "*",
"filter_by": "id:!=674a833de7a564b77c9ef2da && statusCode:=1 && isPopularUser:!=true && profileVerified:=false && age:[18..80] && gender:=[Man, Woman, Non-Binary] && geoLocation:(51.5072, 0.1276, 10 km)",
"sort_by": "geoLocation(51.5072, 0.1276):asc",
"page": 1,
"per_page": 30
}
]
}' | jq '.results[].search_time_ms'
798
To speed this up more, you want to add range_index: true
to the age
field in the collection schema, given the type of numeric comparison you're doing in the filter_by
. You also want to use gender:[...]
instead of gender:=[]
. If you search the docs for exact vs non-exact match, you'll find what this does