Select solr docs where one field is excellent than another

What is the syntax for selecting solr documents where one field is larger than another?

In particular, this is for two fields containing dates.

+4
source share
2 answers

Search for all documents where date_A> date_B is not supported.

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

+6
source

I found this question looking for the same. As it turned out, you can filter by comparison fields using a filter , especially frange and sub.

frange can take the lower bound l or the upper bound u , or both. The optional values incl and incu tell the filter if borders are on or not.

sub subtracts literal numbers or document fields.

So, the answer is to add a filter that only accepts documents where A minus B is greater than zero. Set the lower border to 0, lower the upper border and set incl to false to exclude the lowest border (to delete 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)

+16
source

Source: https://habr.com/ru/post/1403700/


All Articles