choose solr documents where one field is great tha

2020-06-19 21:37发布

问题:

What is the syntax for choosing solr documents where one field is great than another?

More specifically, this is for two fields that contains dates.

回答1:

Finding all docs where date_A>date_B is not supported.

If you are only comparing data_A and date_B, then you could index another field date_a_greater_than_date_b:true for documents when date_A>date_B.



回答2:

I found this question looking for the same thing. As it turns out, you can filter by field comparisons using a filter query, particularly frange and sub.

frange can take a lower bound l or an upper bound u, or both. Optional values incl and incu inform the filter if the boundaries are inclusive or not.

sub subtracts the literal numbers or document fields.

So the answer is to add a filter that accepts only those documents where A minus B is greater than zero. Set the lower bound to 0, omit the upper bound, and set incl to false to exclude the lower bound itself (to remove documents where A==B)

fq={!frange l=0 incl=false}sub(A,B)

URL Encoded: fq=%7B!frange+l%3D0+incl%3Dfalse%7Dsub(A%2CB)



标签: solr