Is it possible to concatenate two fields while indexing JSON in Solr with an update request?

Viewed 24

I'm looking into indexing JSON files with cURL and I'm not sure how I can concatenate two fields while indexing JSON. Take this example from the Solr documentation:

curl 'http://localhost:8983/solr/techproducts/update/json/docs'\
'?split=/exams'\
'&f=first:/first'\
'&f=last:/last'\
'&f=grade:/grade'\
'&f=subject:/exams/subject'\
'&f=test:/exams/test'\
'&f=marks:/exams/marks'\
 -H 'Content-type:application/json' -d '
{
  "first": "John",
  "last": "Doe",
  "grade": 8,
  "exams": [
    {
      "subject": "Maths",
      "test"   : "term1",
      "marks"  : 90},
    {
      "subject": "Biology",
      "test"   : "term1",
      "marks"  : 86}
  ]
}'

I would like to add a query parameter for an ID that would be something like

'&f=id:concat(first,last,exams/subject)'

Is this possible via the current API?

1 Answers

You can add the below entry in solrCOnfig.xml under the <updateRequestProcessorChain name="concatFields">

<processor class="solr.ConcatFieldUpdateProcessorFactory"> 
        <str name="fieldName">field4</str> 
        <str name="delimiter">_</str> 
    </processor>

After adding the update chain, the next step is to add that chain to the appropriate update handler, in this case the CSV handler.

<requestHandler name="/update/csv" class="solr.UpdateRequestHandler">
     <lst name="defaults">
     <str name="stream.contentType">application/csv</str>
     <str name="update.chain">concatFields</str>
   </lst>
</requestHandler>
Related