Solr Indexing and required fields.

Eric Boyer eric.boyer at firmex.com
Tue May 15 15:06:28 EDT 2012


Hey all,

They summary of the problem is: 'required' fields are only honoured
when the field exists in the Solr document with no value, not when the
field doesn't even exist in the POST content.

We've implemented solr search on a bucket called 'objectmetadata'
which has a schema close to the following:

{
    schema,
    [
        {version, "1.1"},
        {default_field, "text"},
        {default_op, "or"},
        {n_val, 3},
        {analyzer_factory, {erlang, text_analyzers,
whitespace_analyzer_factory}}
    ],
		%%unique id of this object, probably something like tag-{objid}
		{field, [
			{name, "id"},
			{required, true},
			{analyzer_factory, {erlang, text_analyzers, noop_analyzer_factory}}
			]},
		%%primary id
		{field, [
			{name, "objid"},
			{type, integer},
			{required, true},
                        {padding_size, 10}
			]},
		{field, [
			{name, "projectid"},
			{type, integer},
			{required, true},
			{inline, true},
                        {padding_size, 10}
			]},

.... }

When posting documents (with "Content-Type: text/xml" header) without
the field :
POST http://riak.local/solr/objectmetadata/update
<add>
<doc>
<field name="id">tag__1</field>
<field name="objid">1</field>
</doc>
</add>
Results in 200 OK

When posting documents with the field but without a value results in:
POST http://riak.local/solr/objectmetadata/update
<add>
<doc>
<field name="id">tag_1_1</field>
<field name="objid">1</field>
<field name="projectid"></field>
</doc>
</add>
Results in 400 Bad Request: "Unable to parse request:
{expected_binaries,<<"projectid">>,[]}"

I would have expected these 2 scenarios to result in the same error.

Anything that I'm missing or is it just my assumption about how
required fields are handled is flawed?

Thanks,
Eric Boyer
Platform Developer
Firmex




More information about the riak-users mailing list