Reputation: 1460
I am importing data from mysql db into solr documents. All is fine but I have one table which has a compound key (a pair of columns together as primary key) -> primary key for post_locations table is (post_id, location_id). But my post_id is the primary key for my solr document, so when data is being imported from post_location table the location_ids are being overwritten.Is it possible to get location_ids(which is of type int) as an array(as there can be more than one location_id for a post).
Upvotes: 1
Views: 153
Reputation: 52892
For MySQL you can use GROUP BY
and GROUP_CONCAT
to get all the values for a field grouped together in a single column, separated by ,
. You can then use the RegexTransformer
and splitBy
for that field to index the field as multiValued
(in practice indexing it as an array). I posted an example of this in a previous answer. You might also do this by having dependent entity entries in DIH, but it will require more SQL queries than doing a GROUP BY
and GROUP_CONCAT
.
If you want one row for each entry, you can use build a custom uniqueKey
instead, using CONCAT
to build the aggregate / compound key on the MySQL side.
Upvotes: 1