Subscribe

Close

Thank you for visiting!

Please consider subscribing to the RSS feed or following me on Twitter.

Archive June 2011:

Delete Documents From Solr Index By Query

If you simply want to delete documents from your Solr index by using the web interface, here's a code snippet that lets you do so:

http://localhost:8983/solr/update?stream.body=
<delete><query>id:298253</query></delete>&commit=true

This lets you delete documents where the id field matches 298253.

If you want to delete items that matches more than one field, just add another query:

http://localhost:8983/solr/update?stream.body=
<delete><query>id:298253</query>
<query>entitytype:BlogEntry</query></delete>&commit=true

If you want to delete all items in the index, just use this query:

<delete><query>*:*</query></delete>

Web Services And AutoEventWireUp

If you get the NullReferenceException error when dealing with web services, it might have to do with AutoEventWireUp being set to false. If you get an error pointing at something like foreach (ServiceDescription description in serviceDescriptions), it might also have to do with AutoEventWireUp set to false.

For instance, if you set AutoEventWireUp to false globally, in Web.Config, your web services will fail.

There's a fix for this though, although it's a bit of a different one.

You just have to locate the DefaultWsdlHelpGenerator.aspx file in C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG (or similar) and add this line to the top:

<%@ Page AutoEventWireup="true" %>

Java Heap Space OutOfMemoryError When Using Solr And Apache

If you get the Java Heap Space OutOfMemoryError in Apache Tomcat, then there's quite an easy fix *.

In Apache Tomcat, you can customize the memory settings, thus allowing more memory to Java clients like Solr.

Just fire up "Configure Tomcat", click on the "Java" tab and allocate enough memory in the "Initial memory pool" and "Maximum memory pool" fields:

Apache Tomcat 7 Java Memory settings

What memory size should you allocate here? Well, it depends. The default initial memory pool is 64 MB. If you've got a pretty large search index with many searches, you'll surelly need more memory allocated.

In a project here, where we've got approximately 20 Million indexed items being searched, 256 MB weren't enough as initial memory pool. 512 MB so far seems to work it out. I guess you just have to try some different values out, and monitor Tomcat's performance while fine-tuning.

* Also take a look at my other blog post on Java heap space issues and 32 / 64 bit versions of Apache Tomcat and Java.

Solr Indexing And The Unique Key Field

If you encounter problems with Solr indexing and inconsistencies in the actual indexing - you might have a problem with the Solr unique key field.

If you index items that may have the same id, and this id is used as the unique key in Solr - then you have a problem. Items with the same id's will simply not be tolerated in the Solr index, thus the latter item overwrites the former when indexing. Of course, this is a default and correct behaviour from Solr.

However - this is easy to solve. You just have to use the UUID (Universal Unique Identifier) field type in Solr.

In schema.config in your Solr conf folder (normally C:/solr/conf or similar), add the UUID type, like this:

<fieldType name="uuid" class="solr.UUIDField" indexed="true" />

Then, add a field of this type (still in schema.config):

 <field name="uid" type="uuid" indexed="true" stored="true"
	default="NEW" />

Finally, make sure to point out this field as the unique key, in schema.config:

<uniqueKey>uid</uniqueKey>

All done! Now all your indexed items will have a unique ID.

Here's more documentation on Solr and the UniqueKey field.

To the top