You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Ariel Zerbib <ar...@gmail.com> on 2013/04/11 16:32:29 UTC

solr join use case (not in instead of in)

Solr has implemented from version 4 the !join query.

I'd like to know if the following  case is possible.
For example, we have documents of the following form:
   doc1:
        field1:123
        field2:A
        field3:456
   doc2:
       field1:123
       field2:B
       field3:789
    doc3:
       field1:23456
       field2:A
       field3:264

We need to retrieve all the documents that the field field2 equals to
B and no other document with the same field field1 value containing
the field field2 with value A.

In SQL this can be done with the operation "not in": select * from doc
where field2 = 'B' and field1 not in (select field1 from doc where
field2 = 'A')

The join operator is the equivalent of the SQL in operator.

Can we use the solr join or another function to implements our needs?

Thanks

Re: solr join use case (not in instead of in)

Posted by Jack Krupansky <ja...@basetechnology.com>.
Generally, you need to flatten and denormalize your data before you place it 
in Solr. But, Solr does have a limited join capability that does handle some 
cases reasonably well:

http://wiki.apache.org/solr/Join

For example...

"This Solr request...

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

Is comparable to this SQL statement...

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

This looks reasonably close to your case.

-- Jack Krupansky

-----Original Message----- 
From: Ariel Zerbib
Sent: Thursday, April 11, 2013 10:32 AM
To: solr-user@lucene.apache.org
Subject: solr join use case (not in instead of in)

Solr has implemented from version 4 the !join query.

I'd like to know if the following  case is possible.
For example, we have documents of the following form:
   doc1:
        field1:123
        field2:A
        field3:456
   doc2:
       field1:123
       field2:B
       field3:789
    doc3:
       field1:23456
       field2:A
       field3:264

We need to retrieve all the documents that the field field2 equals to
B and no other document with the same field field1 value containing
the field field2 with value A.

In SQL this can be done with the operation "not in": select * from doc
where field2 = 'B' and field1 not in (select field1 from doc where
field2 = 'A')

The join operator is the equivalent of the SQL in operator.

Can we use the solr join or another function to implements our needs?

Thanks