I need to run a JOIN query on a solr index. I've got two xmls that I have indexed, person.xml and subject.xml.
Person:
<doc>
<field name="id">P39126</field>
<field name="family">Smith</field>
<field name="given">John</field>
<field name="subject">S1276</field>
<field name="subject">S1312</field>
</doc>
Subject:
<doc>
<field name="id">S1276</field>
<field name="topic">Abnormalities, Human</field>
</doc>
I need to only display information from the person doc but each query should match fields in both person and subject. In the case the query matches only the subject doc I need to display all docs from the person that have a matching id. Is this possible to do without running two seperate queries? Something like a JOIN query would do the job.
Any help?
I do not think it is possible to do what you are asking with a single query using your schema.
One thing that you should keep in mind is to always think of Solr indexes as single denormalized tables. This is sometimes a challenge and there may be times where you must be forced to use different indexes for each kind of data.
For your problem, maybe having a schema like this one might help:
<doc>
<field name="id">P39126</field>
<field name="family">Smith</field>
<field name="given">John</field>
<field name="topic">Abnormalities, Human</field> <!-- subject S1276 -->
<field name="topic">some, other, topics</field> <!-- subject S1312 -->
</doc>
Running a query for some topics with this schema would return all person having those topics.
Some links that might interest you:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With