<?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>identifier &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/identifier/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>Thu, 12 Nov 2020 13:01:13 +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>Automatically Generate Document Identifiers &#8211; Solr 4.x</title>
		<link>https://solr.pl/en/2013/07/08/automatically-generate-document-identifiers-solr-4-x/</link>
					<comments>https://solr.pl/en/2013/07/08/automatically-generate-document-identifiers-solr-4-x/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 08 Jul 2013 12:00:43 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[identifier]]></category>
		<category><![CDATA[solr]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=560</guid>

					<description><![CDATA[A few days ago I got a question regarding the automatic identifiers of documents in Solr 4.0, because the method from Solr 3 was deprecated. Because of that we decided to write a quick post about how to use Solr]]></description>
										<content:encoded><![CDATA[<p>A few days ago I got a question regarding the automatic identifiers of documents in Solr 4.0, because the method from Solr 3 was deprecated. Because of that we decided to write a quick post about how to use Solr to generate documents unique identifier in Solr 4.x.</p>
<p><span id="more-560"></span></p>
<h3>Data structure</h3>
<p>Our simple data structure (<em>fields</em> section of the <em>schema.xml</em> file) looks as follows:
</p>
<pre class="brush:xml">&lt;fields&gt;
 &lt;field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" /&gt;
 &lt;field name="name" type="text_general" indexed="true" stored="true"/&gt;
 &lt;field name="_version_" type="long" indexed="true" stored="true"/&gt;
&lt;/fields&gt;</pre>
<p>In addition to that we&#8217;ve added the information about which field is the one that should contain unique identifiers. This was also done in <em>schema.xml</em> file:
</p>
<pre class="brush:xml">&lt;uniqueKey&gt;id&lt;/uniqueKey&gt;</pre>
<h3>Solr configuration</h3>
<p>In addition to changes in the <em>schema.xml</em> file, we need to modify the <em>solrconfig.xml </em>file and introduce a proper <em>UpdateRequestProcessorChain</em>, like the following one:
</p>
<pre class="brush:xml">&lt;updateRequestProcessorChain&gt;
 &lt;processor class="solr.UUIDUpdateProcessorFactory"&gt;
  &lt;str name="fieldName"&gt;id&lt;/str&gt;
 &lt;/processor&gt;
 &lt;processor class="solr.LogUpdateProcessorFactory" /&gt;
 &lt;processor class="solr.RunUpdateProcessorFactory" /&gt;
&lt;/updateRequestProcessorChain&gt;</pre>
<p>By doing this we inform Solr that we want the <em>id</em> field contents to be automatically generated.</p>
<h3>A simple test</h3>
<p>Let&#8217;s test what we did. In order to do that we will index a simple document by using the following command:
</p>
<pre class="brush:bash">curl -XPOST 'localhost:8983/solr/update?commit=true' --data-binary '&lt;add&gt;&lt;doc&gt;&lt;field name="name"&gt;Test&lt;/field&gt;&lt;/doc&gt;&lt;/add&gt;' -H 'Content-type:application/xml'</pre>
<p>If everything went well the above document was indexed. In order to check what happened we will send a simple query and look at the results. In order to do that we use the following comand:
</p>
<pre class="brush:bash">curl -XGET 'localhost:8983/solr/select?q=*:*&amp;indent=true'</pre>
<p>The result returned by Solr for the above command is as follows:
</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;response&gt;
 &lt;lst name="responseHeader"&gt;
  &lt;int name="status"&gt;0&lt;/int&gt;
  &lt;int name="QTime"&gt;0&lt;/int&gt;
  &lt;lst name="params"&gt;
   &lt;str name="indent"&gt;true&lt;/str&gt;
   &lt;str name="q"&gt;*:*&lt;/str&gt;
  &lt;/lst&gt;
 &lt;/lst&gt;
 &lt;result name="response" numFound="1" start="0"&gt;
  &lt;doc&gt;
   &lt;str name="name"&gt;Test&lt;/str&gt;
   &lt;str name="id"&gt;1cdee8b4-c42d-4101-8301-4dc350a4d522&lt;/str&gt;
   &lt;long name="_version_"&gt;1439726523307261952&lt;/long&gt;
  &lt;/doc&gt;
 &lt;/result&gt;
&lt;/response&gt;</pre>
<p>As we can see the unique identifier was automatically generated. Now if we would send the same indexing command once again:
</p>
<pre class="brush:bash">curl -XPOST 'localhost:8983/solr/update?commit=true' --data-binary '&lt;add&gt;&lt;doc&gt;&lt;field name="name"&gt;Test&lt;/field&gt;&lt;/doc&gt;&lt;/add&gt;' -H 'Content-type:application/xml'</pre>
<p>And run the same query again:
</p>
<pre>curl -XGET 'localhost:8983/solr/select?q=*:*&amp;indent=true'</pre>
<p>We would get two documents in results, just like the following:
</p>
<pre class="brush:xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;response&gt;
 &lt;lst name="responseHeader"&gt;
  &lt;int name="status"&gt;0&lt;/int&gt;
  &lt;int name="QTime"&gt;1&lt;/int&gt;
  &lt;lst name="params"&gt;
   &lt;str name="indent"&gt;true&lt;/str&gt;
   &lt;str name="q"&gt;*:*&lt;/str&gt;
  &lt;/lst&gt;
 &lt;/lst&gt;
 &lt;result name="response" numFound="2" start="0"&gt;
  &lt;doc&gt;
   &lt;str name="name"&gt;Test&lt;/str&gt;
   &lt;str name="id"&gt;1cdee8b4-c42d-4101-8301-4dc350a4d522&lt;/str&gt;
   &lt;long name="_version_"&gt;1439726523307261952&lt;/long&gt;
  &lt;/doc&gt;
  &lt;doc&gt;
   &lt;str name="name"&gt;Test&lt;/str&gt;
   &lt;str name="id"&gt;9bedcb5f-1b71-4ab7-80a9-9882a6bf319e&lt;/str&gt;
   &lt;long name="_version_"&gt;1439726693819351040&lt;/long&gt;
  &lt;/doc&gt;
 &lt;/result&gt;
&lt;/response&gt;</pre>
<p>As you can see, the two above documents have different unique identifiers, so the functionality works.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2013/07/08/automatically-generate-document-identifiers-solr-4-x/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
