<?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>request &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/request/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>
	</channel>
</rss>
