Question

I am using the following code in my solr project:

<document>
<entity name="node" dataSource="opennms" query="select * from node" deltaImportQuery="select * from node">
<field column="foreignid" name="id"/>
<field column="nodelabel" name="label"/>
</entity>
<entity name="service" dataSource="opennms" query="select * from service" deltaImportQuery="select * from service">
<field column="serviceid" name="id"/>
<field column="servicename" name="service_name"/>
</entity>
</document>

The id's of both the entities are the same in some cases. The problem is when i try to import the data, the id which are there in the first table gets overwritten by the id in the second table. Is there a way that i can get both of these uniquely?

Was it helpful?

Solution

I think this totally normal since id column in solr schema was declared as uniquekey. Work around that we do when we encountered same problem was we concatenated the table name with the id to make it unique. In your chase, something like:

select concat('node-', id) as nodeId from node

and

select contact('service-', id) as serviceId from service

concat function will vary on kind of database that your are using.

OTHER TIPS

Ids in Solr needs to be unique. If you insert Entities with the same Ids the previous record would get overwritten.
Solr does not update records. It deletes and reinserts the records.
If you want both the records, define a unique id.
e.g. Prepend Node and Service to the id so that Nodes and services don't overwrite each other.

SELECT A.*, 'NODE_' || ID PRIMARY_ID FROM NODE A

SELECT A.*, 'SERVICE_' || ID PRIMARY_ID FROM SERVICE A
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top