You can post your documents in solr to index in many ways. XML,JSON,CSV are all the supported formats. Apart from this you can directly link solr to database using DataImportHandler, and execute fullImport to index all the data. As use of JSON and RESTful apis are rising day by day so i thought to update the solr using both of them.
For calling rest-apis , i am using ruby gem rest-client. You can use any tool or native methods.
To give you all a clear context , these are the fields in my schema.xml.
schema has 4 fields which are id , name , address and fullText. fullText is a copyField so all the content should be copied here automatically.id is the unique field. name is a mutlivalued field so we need to pass a array in json format to update this.
Sample JSON document to Update:
For each document you update, you have to put it under keys “add” and “doc” like this way:
Format for updating multiple documents:
There are other options you can send along with document to solr.There should be added on ‘add’ level. These are:
commitWithin: 5000 (commit this document within 5 seconds)
overwrite: false (default = true . Don’t check for existing documents with the same uniqueKey)
boost: 3.45 (boost factor for document)
Calling Rest Api to update solr:
After doing this you check for this document in solr, you would not find it. Strange right?
Yes, you have to commit the documents to make them searchable in solr.There are many ways to do this:
Restart the solr server.
reload the core.
Update document with option “commitWithin”.(Explained earlier)
Update document with commit=true
Execute commit=true after updating multiple documents.