0
votes

I would like to store and query documents that contain a from-to date range, where the range represents an interval when the document has been valid.

Typical use cases in lucene/solr documentation address the opposite problem: Querying for documents that contain a single timestamp and this timestamp is contained in a date range provided as query parameter. (createdate:[1976-03-06T23:59:59.999Z TO *])

I want to use the edismax parser.

I have found the ms() function, which seems to me to be designed for boosting score only, not to eliminate non-matching results entirely.

I have found the article Spatial Search Tricks for People Who Don't Have Spatial Data, where the problem described by me is said to be Easy... (Find People Alive On May 25, 1977).

Is there any simpler way to express something like

date_from_query:[valid_from_field TO valid_to_field] than using the spacial approach?

1

1 Answers

2
votes

The most direct approach is to create the bounds yourself:

valid_from_field:[* TO date_from_query] AND valid_to_field:[date_from_query TO *]

.. which would give you documents where the valid_from_field is earlier than the date you're querying, and the valid_to_field is later than the date you're querying, in effect, extracting the interval contained between valid_from_field and valid_to_field. This assumes that neither field is multi valued.

I'd probably add it as a filter query, since you don't need any scoring from it, and you probably want to allow other search queries at the same time.