Ah, I never thought about grouping on date ranges, and nesting the faceting
like that. Interesting! I managed to do a quick test query that seems to give
me what I want:
{
"query": "*:*",
"filter": "+category:* +modified:[NOW/DAY-60DAYS TO *]",
"limit": 0,
"facet": {
"ranges": {
"type": "range",
"field": "modified",
"start": "NOW/DAY-60DAYS",
"end": "NOW/DAY",
"gap": "+7DAY",
"sort": "index",
"facet": {
"categories": {
"type": "terms",
"field": "category",
"limit": -1
}
}
}
}
}
But... this query, as well as all the examples, are in json query format, in a
request body. The actual query will be sent using a custom API that only
accepts a regular URL query, with parameters. Any idea how I can rewrite the
json query above into a URL query?
Also, it would be easier to use the result if the ranges were sorted by the
date in descending order, but no matter what I tried I couldn't get it to work.
I thought that "sort": "index desc" should do the trick, but it seems that
index sort can't be reversed?
Alexandre Rafalovitch wrote:
>
> This feels like basic faceting on category, but you are trying to make a
> latest record, rather than count as a sorting/grouping principle.
>
> How about using JSON Facets?
>
> https://lucene.apache.org/solr/guide/8_8/json-facet-api.html
>
> I would do the first level as range facet and do your dates at whatever
> granularity (say 1 week?) and then second level category terms.
>
> Let us know if it works. It is an interesting question.
>
Svenskt Näringsliv är företagsamhetens röst i Sverige. Vi samverkar med 50
arbetsgivar- och branschorganisationer och är den gemensamma rösten för 60 000
företag med nästan 2 miljoner medarbetare. Vår uppgift är att tala för alla
företag och branscher, även de som ännu inte finns men som kan uppstå om
förutsättningarna är de rätta. Ett bättre företagsklimat för ett bättre
Sverige. Det är vårt uppdrag.
Svenskt Näringsliv behandlar dina personuppgifter i enlighet med GDPR. Här kan
du läsa mer om vår behandling och dina rättigheter,
Integritetspolicy<https://www.svensktnaringsliv.se/dataskydd/integritet-och-behandling-av-personuppgifter_697219.html?utm_source=sn-email&utm_medium=email>