You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Chris Wareham <ch...@graduate-jobs.com> on 2019/01/29 16:27:55 UTC

How to specify custom update chain in a SolrJ request

I'm trying to update records in my Solr core, and have configured a 
custom update chain that skips updates to records that don't exist:

<updateRequestProcessorChain name="skipexisting">
    <processor class="solr.LogUpdateProcessorFactory" />
    <processor class="solr.SkipExistingDocumentsProcessorFactory">
      <bool name="skipInsertIfExists">true</bool>
      <bool name="skipUpdateIfMissing">true</bool>
    </processor>
    <processor class="solr.DistributedUpdateProcessorFactory" />
    <processor class="solr.RunUpdateProcessorFactory" />
  </updateRequestProcessorChain>

My SolrJ update code is currently:

for (Map.Entry<Integer, Integer> user : users.entrySet()) {
     SolrInputDocument document = new SolrInputDocument();
     document.addField("id", user.key().toString());
     document.addField("applications", Collections.singletonMap("set", 
user.value()));

     solrClient.add(document);
}

solrClient.commit();

I can't seem to specify the update chain to use and I assume I need to 
use the UpdateRequest class. However, it's not clear how I go about 
setting a parameter on the UpdateRequest in order to specify the update 
chain.

Chris

Re: How to specify custom update chain in a SolrJ request

Posted by Chris Wareham <ch...@graduate-jobs.com>.
Answering myself, the solution is to update my code as follows:

UpdateRequest request = new UpdateRequest();
request.setParam("update.chain", "skipexisting");

for (Map.Entry<Integer, Integer> user : users.entrySet()) {
     SolrInputDocument document = new SolrInputDocument();
     document.addField("id", user.key().toString());
     document.addField("applications", Collections.singletonMap("set", 
user.value()));

     request.add(document);
     request.process(solrClient);
}

solrClient.commit();

On 29/01/2019 16:27, Chris Wareham wrote:
> I'm trying to update records in my Solr core, and have configured a 
> custom update chain that skips updates to records that don't exist:
> 
> <updateRequestProcessorChain name="skipexisting">
>     <processor class="solr.LogUpdateProcessorFactory" />
>     <processor class="solr.SkipExistingDocumentsProcessorFactory">
>       <bool name="skipInsertIfExists">true</bool>
>       <bool name="skipUpdateIfMissing">true</bool>
>     </processor>
>     <processor class="solr.DistributedUpdateProcessorFactory" />
>     <processor class="solr.RunUpdateProcessorFactory" />
>   </updateRequestProcessorChain>
> 
> My SolrJ update code is currently:
> 
> for (Map.Entry<Integer, Integer> user : users.entrySet()) {
>      SolrInputDocument document = new SolrInputDocument();
>      document.addField("id", user.key().toString());
>      document.addField("applications", Collections.singletonMap("set", 
> user.value()));
> 
>      solrClient.add(document);
> }
> 
> solrClient.commit();
> 
> I can't seem to specify the update chain to use and I assume I need to 
> use the UpdateRequest class. However, it's not clear how I go about 
> setting a parameter on the UpdateRequest in order to specify the update 
> chain.
> 
> Chris