Import data from JSON to solr

I am currently using an XML file in solr. I index xml file data using DataimportHandler with XPathentityProcessor.

Now I want to import data from a json file.

Is there any example?

Regards, Sagar

+7
source share
6 answers

What you need is something like

curl 'http://localhost:8983/solr/update/json?commit=true' --data-binary @books.json -H 'Content-type:application/json' 

Taken from the example.

Source: https://wiki.apache.org/solr/UpdateJSON

+6
source

DataImportHandler does not allow using JSON as a source. The only way is to use an update handler that can handle JSON natively. But it should be in the JSON structure that Solr expects (an array of hashes or a hash of commands / hashes).

+3
source

If you do not want to use the curl command, you can run the command directly in the browser and get the desired result:

 http://`localhost`:8983/solr/update/json?commit=true --data-binary @books.json -H 'Content-type:application/json' 

Put the json file in the / example / exampledocs folder. This is the path to the default directory in solr. If you use java or php, etc., That is, there are several classes and methods that you use, and then you do not need to mention the whole command, as indicated above. Is this what you are asking for?

+3
source

You can also update your documents by including curl commands in the url text, for example, the commit = true statement.

 curl -X POST -H "Content-Type: application/json" -u "{usernamne}":"{password}" "https://your_host/solr/your_collection/update/json?commit=true" --data-binary @/path/to/your/data/your_data.json 
+1
source

You can use REST api to send data to Solr. Use this way:

 localhost:8983/solr/simple2/update?commit=true //(simple2 is the core name and localhost:8983 is server path.) 

and you must define

 :content_type => 'application/json' 

in the request header. Alternatively, you can send the json file / data to solr using a post request.

For more information, visit http://geekdirt.com/blog/indexing-in-solr-using-json-and-rest-apis/

0
source

If you want to import part or all of the collection from the json format, well, there is an alternative.

I wrote a java tool: https://github.com/freedev/solr-import-export-json

This is a Java application that imports and exports a collection of Solr using SolrJ . Each document must be a json object, and in the imported file you must have a list of lines, while each line is a json object.

 { "id": 1, "date": "20160101T00:00:00", "text": "some text" } { "id": 2, "date": "20160102T00:00:00", "text": "some text" } { "id": 3, "date": "20160103T00:00:00", "text": "some text" } 

I have not tried nested documents, and json document keys must be exactly Solr field names.

0
source

All Articles