Consider this situation,

I've got documents, for which I'll have to store multiple dates, those could be 
access dates for example, or maybe "downloaded at"-dates or something similar.

So, a document might look like this:

{id:"1", name:"apache-solr-ref-guide-7.3.pdf", 
downloaded_at:{"2018-01-01T00:00:00Z", "2018-01-02T00:00:00Z", 
"2018-03-16T00:00:00Z", "2018-03-17T00:00:00Z"}

My question is, how would I write a query which will return all documents 
downloaded between i.e. 2018-02-01 and 2018-04-12 and provides additionally the 
count of downloads within the given date range of this document?

So considering an index consisting only of the example doc provided above, I'd 
like to get a result like this:

result: 1 document, with name:"apache-solr-ref-guide-7.3.pdf", 
count_of_downloads:2 (2, since within the "downloaded_at"-field, two out of the 
four dates lie within the filtered date range)

I've thought of two possible approaches on how I'd need to store information in 
order to be able to execute such a query, but I am not sure any of these would 
actually make such a query possible.

A) store the dates in a multivalued field and see if I can both, filter the 
multivalued field on a date range and somehow, maybe using some function query, 
can also obtain the count of matches within the multivalued field
or B) introduce these dates as nested child documents, filtering on that date 
range and somehow get the number of matching child documents into the result

I guess filtering for that given date range will be easy, but how about getting 
the count of matches within the multivalued field, respectively the count of 
matching child documents into the result?

Best regards, and as always thanks for reading!

Sebastian

Reply via email to