I try to change Solr schema before DIH to fit it to SQL query result. I use my custom proccesor and in init method i add new fields in schema:
@Override
public void init(Context context) {
super.init(context);
String mode = (String) context.getRequestParameters().get("command");
if (mode.equals("full-import")) {
Map<String, Object> row = this.nextRow();
Set<String> fields = context.getSolrCore().getLatestSchema().getFields().keySet();
IndexSchema schema = context.getSolrCore().getLatestSchema();
Map<String, Object> fieldAttributes = new LinkedHashMap<>();
fieldAttributes.put("stored", true);
fieldAttributes.put("indexed", true);
for (Map.Entry<String,Object> entry : row.entrySet()) {
if (!fields.contains(entry.getKey())) {
SchemaField schemaField = schema.newField(entry.getKey(), "string", fieldAttributes);
schema = schema.addField(schemaField);
}
}
context.getSolrCore().setLatestSchema(schema);
}
rowIterator = null;
}
All works, but import go by old schema (i had only 3 fields at start). I see changes on schema after first import. If i restart import again - all works good, and i see all my new fields with their values.
How to point Solr to the new schema and do not restart import?
UPDATE:
I extend SqlEntityProcessor
public class KinefProccessor extends SqlEntityProcessor {
@Override
public void init(Context context) {
super.init(context);
String mode = (String) context.getRequestParameters().get("command");
....
....
And my config:
<dataConfig>
<dataSource driver="org.postgresql.Driver" url="jdbc:postgresql://*******" user="***" password="***" />
<document>
<entity name="item" query="****" processor = "KinefProccessor">
<field column="v.id" name="id" />
</entity>
</document>
</dataConfig>