Can you not calculate on the fly when the date which is one month before the current is and use that as your upper limit?
e.g. taking today as an example your upper limit would be 20011-02-04T00:00:00Z and so your query would be something like: q=products:Dog AND saledate:[* TO 20011-02-04T00:00:00Z] On 4 March 2011 11:40, Peter Sturge <peter.stu...@gmail.com> wrote: > Hello, > > I've been wrestling with a query use case, perhaps someone has done this > already? > Is it possible to write a query that excludes results based on another > query? > > Scenario: > I have an index that holds: > 'customer' (textgen) > 'product' (textgen) > 'saledate' (date) > > I'm looking to return documents for 'customer' entries who have bought a > 'product' in the past, but haven't bought in, say, the last month. > (i.e. need to exclude *all* 'customer' documents who have bought 'product' > in the last month, as well as those who have never bought 'product') > > A very simple query like this: > q=products:Dog AND -(products:Dog AND saledate:[2011-01-01T00:00:00Z TO > *]) > returns 'Dog' documents prior to 1 Jan, but these need to be excluded if > there are matches after 1 Jan. > I wasn't expecting the above query to do the extra exclusion - it's just to > illustrate the general problem that it operates at document level, not > query > level (like a SQL subquery). > If I could could pipe the results of the above to another query, that would > likely do the trick. > I've tried negative boosts, magic _query_, query() and such, but with no > luck. > > Is this possible? > Any insight into how to write such a query would be much appreciated! > > Thanks, > Peter >