<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>json &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/json-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://solr.pl/en/</link>
	<description>All things to be found - Blog related to Apache Solr &#38; Lucene projects - https://solr.apache.org</description>
	<lastBuildDate>Sat, 14 Nov 2020 13:57:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Solr 5 &#8211; JSON Request API, part one</title>
		<link>https://solr.pl/en/2015/12/21/solr-5-json-request-api-part-one/</link>
					<comments>https://solr.pl/en/2015/12/21/solr-5-json-request-api-part-one/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 21 Dec 2015 13:57:01 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[5]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[solr]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=879</guid>

					<description><![CDATA[Solr 5 introduced a lot of changes to the world of the API&#8217;s and functionalities around Solr. JSON API and facets were the one that were moved from HeliosSearch project and resulted in users being able to send queries using]]></description>
										<content:encoded><![CDATA[<p>Solr 5 introduced a lot of changes to the world of the API&#8217;s and functionalities around Solr. JSON API and facets were the one that were moved from HeliosSearch project and resulted in users being able to send queries using JSON, which is a bit more human friendly compared to long queries constructed as URI. In this post we will introduce you to the world on JSON request API in Solr.</p>
<p><span id="more-879"></span></p>
<h2>Running a query</h2>
<p>I&#8217;m sure you are familiar on how to run queries to Solr in the standard, old fashioned way, right? So, to get documents that match the <em>solr</em> term in the <em>_text_</em> field we would just run a command like this:
</p>
<pre class="brush:xml">curl -XGET 'localhost:8983/solr/gettingstarted/select?q=_text_:solr&amp;indent=true'
</pre>
<p>Just for the record, I&#8217;m using the schemaless example provided with Solr and I indexed the data from the <em>docs</em> directory.</p>
<p>We can do the same using the JSON API of Solr. For example, a JSON structured query that would return exactly the same results as the one shown above would look as follows:
</p>
<pre class="brush:xml">curl -XGET 'localhost:8983/solr/gettingstarted/query' -d '{
 "query":"_text_:solr"
}'
</pre>
<p>As you can see, we just specify the query using a JSON object and the query property in it and we send it as a request body to the <em>/query</em> handler. We could also send the query to the <em>/select</em> handler, but the <em>/query</em> one uses JSON response by default, so it seems more appropriate for JSON queries <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>We can also use the standard parameter names and pass them in the body of the request, just like this:
</p>
<pre class="brush:xml">curl -XGET 'localhost:8983/solr/gettingstarted/query' -d 'q=_text_:solr'
</pre>
<p>So, this time we didn&#8217;t have the JSON structure in the request body, we just pass the parameters there and separate them with <em>&amp;</em> character, just like when sending a query using URI request.</p>
<h2>Paging</h2>
<p>Of course, we can also page through the results when using JSON API. We do that by using the <em>limit</em> and and <em>offset</em> parameters. The <em>limit</em> parameter specifies the maximum number of returned documents and the <em>offset</em> parameter is responsible for telling Solr from which document the results should be returned. For example, to get 20 documents starting from the 11th one, we would run the following query:
</p>
<pre class="brush:xml">curl -XGET 'localhost:8983/solr/gettingstarted/query' -d '{
 "query":"_text_:solr",
 "limit":20,
 "offset":10
}'
</pre>
<h2>Sorting</h2>
<p>The next thing is the ability to sort the results and we can do that using Solr JSON API as well. To sort our results on the basis of the <em>id</em> field, in the descending order we would run the following query:
</p>
<pre class="brush:xml">curl -XGET 'localhost:8983/solr/gettingstarted/query' -d '{
 "query":"_text_:solr",
 "sort":"id desc"
}'
</pre>
<p>It is very similar to what we are used to when using the standard URI request queries, but we are using the <em>sort</em> property.</p>
<h2>Filtering</h2>
<p>Finally, we have filtering. We can filter our data by using the <em>filter</em> property. For example, to narrow down our data to only the ones that have <em>text/html</em> value in the <em>content_type</em> field we would run the following query:
</p>
<pre class="brush:xml">curl -XGET 'localhost:8983/solr/gettingstarted/query' -d '{
 "query":"_text_:solr",
 "filter":"content_type:text/html"
}'
</pre>
<h2>What&#8217;s next</h2>
<p>As you can see the JSON API of Solr is very easy to use and allows us to use more structured queries when talking to Solr. In the next entry we will discuss the JSON facets API, how to use it and what are other differences when it comes to JSON facets and the traditional implementation, because making the request is not the only difference when we compare those two.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2015/12/21/solr-5-json-request-api-part-one/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Solr 3.1: JSON Update Handler</title>
		<link>https://solr.pl/en/2011/04/18/solr-3-1-json-update-handler/</link>
					<comments>https://solr.pl/en/2011/04/18/solr-3-1-json-update-handler/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 18 Apr 2011 18:42:09 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[file format]]></category>
		<category><![CDATA[handler]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[update]]></category>
		<category><![CDATA[update handler]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=260</guid>

					<description><![CDATA[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]]></description>
										<content:encoded><![CDATA[<p>After the release of <a href="http://solr.pl/en/2011/03/31/lucene-and-solr-3-1/" target="_blank" rel="noopener noreferrer">Solr 3.1</a> 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 &#8211; XML, CSV, and so.  called JavaBin. The release of Solr 3.1 introduces the fourth format &#8211;  JSON.</p>
<p><span id="more-260"></span></p>
<h3>Let&#8217;s start</h3>
<p><em></em>The  new handler (<em>JsonUpdateRequestHandler</em>) 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&#8217;s leave the  performance for now.</p>
<h3>Configuration</h3>
<p>Let&#8217;s start by defining a handler. To  do that add the following definition to the <em>solrconfig.xml </em>file (if you  use the default solrconfig.xml file provided with Solr 3.1 than this  handler is already defined):
</p>
<pre class="brush:xml">&lt;requestHandler name="/update/json" class="solr.JsonUpdateRequestHandler" startup="lazy" /&gt;</pre>
<p>The entry above defines a new handler that will be initialized when used for the first time (<em>startup=&#8221;lazy&#8221;</em>).</p>
<h3>Indexing</h3>
<p>The next step is to prepare the data &#8211; of course in JSON format. Here&#8217;s an example showing two documents in one file called <em>data.json</em>:
</p>
<pre class="brush:plain">{

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

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

}</pre>
<p>Such prepared file can be sent to the <em>/update/json</em> address and thus be indexed. Remember  to send a commit command to the appropriate address (standard <em>/update</em>)  in order to tell Solr to open a new index searcher.</p>
<h3>Performance</h3>
<p>At the end I left myself what I&#8217;m really most interested in &#8211; the performance of the new handler. According  to the information stored in JIRA system we can be expect that <em> JsonUpdateRequestHandler </em>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:</p>
[table “10” not found /]<br />

<p>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 &#8211; 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.</p>
<h3>Indexation time</h3>
<p>Another thing is the indexing time. Leaning  on the results of this simple test we can think that <em> JsonUpdateRequestHandler </em>is slightly (about 7 &#8211; 9%) faster than the <em> XmlUpdateRequestHandler</em>. As  you can see, the difference is similar for <em>JsonUpdateRequestHandler </em>and  <em>CSVRequestHandler</em>, 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&#8217;s  hope that when the <a href="http://labs.apache.org/labs.html" target="_blank" rel="noopener noreferrer">noggit </a>library comes out of Apache Labs, its  performance will be even greater, and thus we will see even faster <em> JsonUpdateRequestHandler</em>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2011/04/18/solr-3-1-json-update-handler/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
