Java index json data to solr

959 Views Asked by At

I try to index json data to solr.

SolrClient solr = new HttpSolrClient.Builder(SOLR_URL).build();
SolrInputDocument document = new SolrInputDocument();
String stringToParse = "{\"id\": \"101\",\"name\": \"Baia Otel\",\"services\":[{\"room_id\":\"1234\",\"service_name\":\"Shuttle\"},{\"room_id\":\"1235\",\"service_name\":\"Accommodation\"}]}";
JSONParser parser = new JSONParser();
try {
    JSONObject json = (JSONObject) parser.parse(stringToParse);
    document.addField("info", json.toJSONString());
} catch (ParseException e) {
    e.printStackTrace();
}

On document.addField method if I use json.toJSONString() it indexes json data as string, and when I just use jsonObject without casting it to JSONString;

document.addField("info",json)

it does not index this field.

How can I index json to solr so that it will be indexed nested?

1

There are 1 best solutions below

0
On

You can find examples of indexing JSON with Solrj for schemaless Solr in this blog.