Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import data from JSON in solr

Tags:

json

solr

Currently I am using XML file in solr. I index xml file's data using DataimportHandler with XPathentityProcessor.

Now I want to import data from json file.

Is there any example ?

Regards, Sagar

like image 724
Sagar Joshi Avatar asked Feb 05 '13 10:02

Sagar Joshi


2 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

like image 90
Tonko Mulder Avatar answered Sep 28 '22 21:09

Tonko Mulder


If you want import part or the entire collection from a 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 Solr collection using SolrJ. Every document has to be a json object and in the file you are importing you must have a list of lines whereas 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 haven't tried with nested documents, and the keys of json document should be exactly the names of the Solr fields.

like image 35
freedev Avatar answered Sep 28 '22 20:09

freedev