I have a numeric timestamp field in our record - w...
# community-help
d
I have a numeric timestamp field in our record - what’s the most efficient way to find out how many records are at intervals of this value? multi_search..?
1
j
@Dan You could do something like:
filter_by: timestamp:>=123 && timestamp:<=345
d
this works great - but I’m wondering if there’s any way I can get counts per interval in a single query, as if it were a facet, for example
ie. with a search for all documents, I want to know how many are in buckets of intervals x > y and y > z etc etc
seems like the only way to get that answer is to do a multi_query, and plumb in the data somehow
j
Yeah multi_search is one way, the other way would be to add a new field to every record called say
timestamp_interval
and set a common value for all records between x > y, and another common value for all records between y > z, and then facet by that field.
For eg, in the songs-search demo: https://songs-search.typesense.org/?songs_1630520530850%5Bquery%5D=Annie%27s%20song%20Denver The actual release date is a unix timestamp, but I created a new field called "Release Date" and extracted just the year into a new string field and I facet by that field for display / filtering purposes, but use the timestamp field for sorting
👍 1
d
works great for absolute dates, but I’m looking for relative dates, sadly
ie, last 7 days, last 30..
j
Ah, then multi_search would be the only way
d
all good. I’ll give it a go 🙂
👍 1
working great.
🙌 1