Cross Core Query

After reading so many examples, you may find that all of them are querying against single core collection, how about query with multiple cores like “JOIN” SQL in database? Don’t worry, SOLR supports it. Before the example, let’s create another core right now:

  1. Make sure your SOLR is running now, open a command prompt and “cd C:/{your_installed_path}/solr-5.4.1/bin/”
  2. Enter “solr create –c director”

  1. Go to http://localhost:8983/solr/#/director/documents , and add the below records:

name,born

Ridley Scott,England

Vikram Bhatt,India

Steven Soderbergh,U.S.

Uwe Boll,West Germany

Brett Ratner,U.S.

 

Ok, data for new core has been prepared, let’s try the cross core queries below:

Requested URL

http://localhost:8983/solr/films/select?q=*:*&fq={!join from=name to=directed_by fromIndex=director}born:India&wt=xml&rows=10

Details

This request has two parts:

1.       Getting list of director names from core “director”

2.       Getting list of films from core “films” where “directed_by” equals to the list of director names

It is something like this: SELECT * FROM FILMS WHERE directed_by IN (SELECT name FROM DIRECTOR).

Parameters Values Details
fq born:India Filter condition to “director” core
from name The field from “director” core
to directed_by Field of “films” core for filtering
fromIndex director From which core

 

If you want to query like: SELECT * FROM FILMS WHERE directed_by NOT IN (SELECT name FROM DIRECTOR), please see the below example:

Requested URL

http://localhost:8983/solr/films/select?q=*:*&fq=(-{!join from=name to=directed_by fromIndex=director}born:India)&wt=xml&rows=10

Details

It is similar to the first example. But, it has a “-“ in the fq, it means NOT equal to.

This request has two parts:

1.       Getting list of director names from core “director”

2.       Getting list of films from core “films” where “directed_by” NOT equals to the list of director names

Parameters Values Details
fq born:India Filter condition to “director” core
from name The field from “director” core
to directed_by Field of “films” core for filtering
fromIndex director From which core

 

Please rate this