In Solr update XML you can initialize a multi-valued field using multiple 
<field> elements for the same field:

  curl http://localhost:8983/solr/update?commit=true \
       -H "Content-Type: application/xml" --data-binary '
<add>
  <doc>
    <field name="id">text-1</field>
    <field name="text_ss" update="set">set-mv-text-value1</field>
    <field name="text_ss" update="set">set-mv-text-value2</field>
  </doc>
</add>'

I would have thought you could do the same with Solr update JSON:

curl http://localhost:8983/solr/update?commit=true \
     -H "Content-Type: application/json" --data-binary '
[{"id": "text-1",
  "text_ss": {"set": "new-text-value1"},
  "text_ss": {"set": "new-text-value2"}
}]'

But, that bizarrely treats the value map as a literal, indexing the field value 
as:

<arr name="text_ss">
  <str>{set=new-text-value2}</str>
  <str>{set=new-text-value1}</str>
</arr>

Granted, the better way is to write the command in JSON using an array of 
values:

curl http://localhost:8983/solr/update?commit=true \
     -H "Content-Type: application/json" --data-binary '
[{"id": "text-1",
  "text_ss": {"set": ["new-text-value1", "new-text-value2"]}
}]'

Which initializes the field as:

<arr name="text_ss">
  <str>new-text-value1</str>
  <str>new-text-value2</str>
</arr>

So, the question is: Was my first command “invalid” and should have thrown an 
exception, or was the treatment of multiple instances of the field name simply 
treated improperly?

Incidentally, I tried:

curl http://localhost:8983/solr/update?commit=true \
     -H "Content-Type: application/json" --data-binary '
[{"id": "text-1",
  "text_ss": {"set": "new-text-value1", "set": "new-text-value2"}
}]'

And it simply used the last value for “set”:

<arr name="text_ss">
  <str>new-text-value2</str>
</arr>

Again, is this contract behavior, invalid and should throw an exception, or a 
bug that should be fixed to do the obvious thing?

-- Jack Krupansky

Reply via email to