Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Solr 3.1+: JSON Update Handler

DZone's Guide to

Solr 3.1+: JSON Update Handler

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

After the release of Solr 3.1 I decided to look into the extended list of formats through which we can update the indexes. Until now we had a choice of three kinds of formats with which we were able to provide data – XML, CSV, and so. called JavaBin. The release of Solr 3.1 introduces the fourth format – JSON.

Let’s start

The new handler (JsonUpdateRequestHandler) allows us to transfer data in the JSON format which in theory should translate into a smaller amount of data sent over the network and the speedup of indexing, as the JSON parser is theoretically faster than XML parsers. But let’s leave the performance for now.

Configuration

Let’s start by defining a handler. To do that add the following definition to the solrconfig.xml file (if you use the default solrconfig.xml file provided with Solr 3.1 than this handler is already defined):

<requestHandler name="/update/json" class="solr.JsonUpdateRequestHandler" startup="lazy" />

The entry above defines a new handler that will be initialized when used for the first time (startup=”lazy”).

Indexing

The next step is to prepare the data – of course in JSON format. Here’s an example showing two documents in one file called data.json:

{

"add": {
  "doc": {
    "id" : "123456788",
    "region" : ["abc","def"],
    "name" : "ABCDEF",
  }
}

,
"add": {
  "doc": {
    "id" : "123456789",
    "region" : ["abc","def"],
    "name" : "XYZMN",
  }
}

}

Such prepared file can be sent to the /update/json address and thus be indexed. Remember to send a commit command to the appropriate address (standard /update) in order to tell Solr to open a new index searcher.

Performance

At the end I left myself what I’m really most interested in – the performance of the new handler. According to the information stored in JIRA system we can be expect that JsonUpdateRequestHandler will be faster than its counterpart processor of XML format. To examine this, I prepared the files of 10.000, 100.000 and 1 million documents. Every document contained an identifier (string field), two regions (String field, multivalued) and the name (text field). One file was saved in the JSON format, the second one was saved in XML format, the third one was saved in CSV format. All files were then indexed separately. Here is an outcome of this simple test:

Number of documents Data weight XML indexing time JSON indexing time CSV indexing time
10.000 JSON:1.19MB
XML:1.88MB
CSV: 394KB
954ms 734ms 732ms
100.000 JSON:12.4MB
XML:19.3MB
CSV: 4.33MB
7656ms 6222ms 6203ms
1.000.000 JSON:129MB
XML:197MB
CSV: 48.1MB
126625ms 119023ms 108234ms

The conclusions suggest themselves. First, XML data is relatively larger than the one written in JSON format (the difference is about 35%). However, a file stored in JSON format, is larger (which might be expected) than the one written in the CSV. If you send data not on the local network, the size is relevant – the difference in file size is significant enough that it is worth thinking about changing the XML to any of the formats that require less space.

Indexation time

Another thing is the indexing time. Leaning on the results of this simple test we can think that JsonUpdateRequestHandler is slightly (about 7 – 9%) faster than the XmlUpdateRequestHandler. As you can see, the difference is similar for JsonUpdateRequestHandler and CSVRequestHandler, where the handler operates on files in CSV format is faster than its counterpart that operates in JSON format by about 7 to 9%. Let’s hope that when the noggit library comes out of Apache Labs, its performance will be even greater, and thus we will see even faster JsonUpdateRequestHandler.

 

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Published at DZone with permission of Rafał Kuć, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}