On Tue, Jul 31, 2012 at 10:16 AM, Jonatan Fournier
<jonatan.fourn...@gmail.com> wrote:
> Hi,
>
> What is the Java syntax to create an update document?
>
> I was using this in JSON to update/reset some fields of document 12345
> (it contains other fields, only updating those):
>
> {
>   "add" : {
>     "doc" : {
>       "id":"12345",
>       "foo":{"set":null},
>       "bar":{"set":"baz"}
>     }
>   }
> }
>
> Now I'm trying to find the equivalent in Java (Embedded Server), I'm doing 
> this:
>
> SolrInputDocument solrDoc = new SolrInputDocument();
> solrDoc.addField( "id", "12345" );
> solrDoc.setField( "foo", null );
> solrDoc.setField( "bar", "baz" );
> server.add( solrDoc );
>
> But instead of updating like with JSON, it overwrites the whole
> document in the index. Something I'm missing?

Sorry I just realized that the setField/addField only applies to the
SolrInputDocument you manipulate, not setting internal flags for the
indexer to treat the SolrInputDocument differently based on if set or
add was called... :)

>
> I also tried:
>
> SolrInputDocument solrDoc = new SolrInputDocument();
> solrDoc.setField( "id", "12345" );
> solrDoc.setField( "foo", null );
> solrDoc.setField( "bar", "baz" );
> server.add( solrDoc );
>
> But it does the same thing. Interesting fact, when using setField()
> and the id doesn't exist it will still create the document, which
> wasn't the case with JSON before Yunik added a change (I'm still using
> 4.0.0-ALPHA, not trunk) I've discussed with him previously on this
> list.
>
> Should we be expecting the same behavior from the API and the http
> JSON/XML/CSV interface?
>
> Cheers,
>
> --jonatan

Reply via email to