Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr join "not in" subselect

Tags:

solr

In the Solr join documentation Solr Join they say that:

/solr/collection1/select ? fl=xxx,yyy & q={!join from=inner_id to=outer_id}zzz:vvv

is equivalent to:

SELECT xxx, yyy
FROM collection1
WHERE outer_id IN (SELECT inner_id FROM collection1 where zzz = "vvv")

How do I write in Solr (see the NOT):

SELECT xxx, yyy
FROM collection1
WHERE outer_id NOT IN (SELECT inner_id FROM collection1 where zzz = "vvv")

Lets consider the following example:
People Records:

1. name='a', id=1, teacherId=4
2. name='b', id=2, teacherId=4
3. name='c', id=3, teacherId=1
4. name='d', id=4, isTeacher='true'

Now I want to select all students which their teacherId points to non teacher ID (record #3).
In SQL:

select * from people where teacherId not in (select id where isTeacher='true').
like image 392
Avner Levy Avatar asked Sep 03 '25 03:09

Avner Levy


1 Answers

I'm faced with this problem too and that's how I resolved it:

q=-_query_:"{!join from=inner_id to=outer_id}zzz:vvv"

You can add this nested query to fq too.

Hope that helps!)

like image 113
Artem Titov Avatar answered Sep 05 '25 01:09

Artem Titov