lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sami Siren <ssi...@gmail.com>
Subject Re: SolrJ: atomic updates.
Date Thu, 15 Nov 2012 14:02:04 GMT
Try setting Request writer to binary like this:

      server.setParser(new BinaryResponseParser());
      server.setRequestWriter(new BinaryRequestWriter());

Or then instead of string array use ArrayList<String>() that contains your
strings as the value for the map


On Thu, Nov 15, 2012 at 3:58 PM, Luis Cappa Banda <luiscappa@gmail.com>wrote:

> Hi, Sami.
>
> Doing some tests I´ve used the same code as you and did a quick execution:
>
>
> *HttpSolrServer server = new HttpSolrServer("
> http://localhost:8080/solrserver/core1<
> http://localhost:10080/newscover_es/items_es>
> ");*
>
> * *
> * try {*
> * *
> * HashMap editTags = new HashMap();*
> *     editTags.put("set", new String[]{"tag1","tag2","tag3"});*
> *     doc.addField("myField", editTags);*
> *     server.add(doc);*
> *     server.commit(true, true);*
> * *
> * } catch (SolrServerException e) {*
> * e.printStackTrace();*
> * } catch (IOException e) {*
> * e.printStackTrace();*
> * }*
> *
> *
> *
> *
> And the resultant doc is wrong:
>
> <response>
>
> <lst name="responseHeader">
>
> <int name="status">0</int>
>
> <int name="QTime">1</int>
>
> <lst name="params">
>
> <str name="q">*:*</str>
>
> </lst>
>
> </lst>
>
> <result name="response" numFound="1" start="0">
>
> <doc>
>
> <str name="i_id">50a0f1f90cf226fb5677fe13</str>
>
> <arr name="myField">
>
> *<str>[Ljava.lang.String;@7d5e90cb</str>   ---> toString() from String[]
> array.*
>
> </arr>
>
> <long name="_version_">1418710023780958208</long>
>
> </doc>
>
> </result>
>
> </response>
>
>
>
> So is definetely executing toString() method in both *HttpSolrServer *and *
> CloudServer*. Tips:
>
>
>    - I´m using* Solrj 4.0.0 *artifact version in a *Maven *project.
>    - The fields to be updated are *dynamicFields*.
>    - I´m using Java jdk6.
>
> Alternatives:
>
>    - I´m doing something wrong and I´m so stupid that I can´t see it, :-(
>    - The way I update fields is not the correct one.
>    - There is a general bug with atomic updates via SolrJ.
>
>
> Regards,
>
>
> - Luis Cappa.
>
>
> 2012/11/15 Luis Cappa Banda <luiscappa@gmail.com>
>
> > I´ll have a look to Solr source code and try to fix the bug. If I succeed
> > I´ll update JIRA issue with it, :-)
> >
> >
> > 2012/11/15 Sami Siren <ssiren@gmail.com>
> >
> >> Actually it seems that xml/binary request writers only behave
> differently
> >> when using array[] as the value. if I use ArrayList it also works with
> the
> >> xml format (4.1 branch). Still it's annoying that the two request
> writers
> >> behave differently so I guess it's worth adding the jira anyway.
> >>
> >> The Affects version should be 4.0.
> >>
> >>
> >> On Thu, Nov 15, 2012 at 1:42 PM, Luis Cappa Banda <luiscappa@gmail.com
> >> >wrote:
> >>
> >> > Hello, Sami.
> >> >
> >> > It will be the first issue that I open so, should I create it under
> Solr
> >> > 4.0 version or in Solr 4.1.0 one?
> >> >
> >> > Thanks,
> >> >
> >> > - Luis Cappa.
> >> >
> >> > 2012/11/15 Sami Siren <ssiren@gmail.com>
> >> >
> >> > > On Thu, Nov 15, 2012 at 11:51 AM, Luis Cappa Banda <
> >> luiscappa@gmail.com
> >> > > >wrote:
> >> > >
> >> > > > Thread update:
> >> > > >
> >> > > > When I use a simple:
> >> > > >
> >> > > > *Map operation = new HashMap();*
> >> > > >
> >> > > >
> >> > > > Instead of:
> >> > > >
> >> > > > *Map<String, List<String>> operation = new HashMap<String,
> >> > > > List<String>>();*
> >> > > >
> >> > > >
> >> > > > The result looks better, but it´s still wrong:
> >> > > >
> >> > > > fieldName: [
> >> > > > "[Value1, Value2]"
> >> > > > ],
> >> > > >
> >> > > >
> >> > > > However,  List<String> value is received as a simple String
> >> "[Value1,
> >> > > > Value2]". In other words, SolrJ is internally executing a
> toString()
> >> > > > operation to the List<Sring>. Is impossible to update atomically
a
> >> > > > multivalued field with a List of values in just one atomic update
> >> > > > operation?
> >> > > >
> >> > >
> >> > > Seems to be working fine here with HttpSolrServer /
> >>  BinaryRequestWriter;
> >> > >
> >> > >     HashMap editTags = new HashMap();
> >> > >     editTags.put("set", new String[]{"tag1","tag2","tag3"});
> >> > >     doc = new SolrInputDocument();
> >> > >     doc.addField("id", "unique");
> >> > >     doc.addField("tags_ss", editTags);
> >> > >     server.add(doc);
> >> > >     server.commit(true, true);
> >> > >     resp = server.query(q);
> >> > >
> >> > System.out.println(resp.getResults().get(0).getFirstValue("tags_ss"));
> >> > >
> >> > > prints "tag1"
> >> > >
> >> > > ArrayList<String> as a value works the same way as String[].
> >> > >
> >> > > When using xml (RequestWriter) I can see the problem that you are
> >> > > describing, can you add a jira for that?
> >> > >
> >> > > --
> >> > >  Sami SIren
> >> > >
> >> > >
> >> > >
> >> > >
> >> > >
> >> > > >
> >> > > > Regards,
> >> > > >
> >> > > >
> >> > > > - Luis Cappa.
> >> > > >
> >> > > > 2012/11/15 Luis Cappa Banda <luiscappa@gmail.com>
> >> > > >
> >> > > > > Hello everyone,
> >> > > > >
> >> > > > > I´ve tested atomic updates via Ajax calls and now I´m
starting
> >> with
> >> > > > atomic
> >> > > > > updates via SolrJ... but the way I´m proceeding doesn´t
seem to
> >> work
> >> > > > well.
> >> > > > > Here is the snippet:
> >> > > > >
> >> > > > > *SolrInputDocument do = ne SolrInputDocument();*
> >> > > > > *doc.addField("id", "myId");*
> >> > > > > *
> >> > > > > *
> >> > > > > *Map<String, List<String>> operation = new HashMap<String,
> >> > > > > List<String>>();*
> >> > > > > *operation.put("set", [[a list of String elements]]);  //
I
> want a
> >> > set
> >> > > > > operation to override field values.*
> >> > > > > *doc.addField("fieldName", operation);*
> >> > > > > *
> >> > > > > *
> >> > > > > *cloudSolrServer.add(doc); // Atomic update operation.*
> >> > > > >
> >> > > > >
> >> > > > > And after updating the resultant doc is as follows:
> >> > > > >
> >> > > > > *doc: {*
> >> > > > > *
> >> > > > > *
> >> > > > > *...*
> >> > > > > *
> >> > > > > *
> >> > > > > *fieldName: [ "{set=values}"*
> >> > > > > *],*
> >> > > > > *
> >> > > > > *
> >> > > > > *...*
> >> > > > >
> >> > > > > *
> >> > > > > *
> >> > > > >
> >> > > > > *}*
> >> > > > >
> >> > > > > In other words, the map which includes the "set" operation
and
> the
> >> > > field
> >> > > > > values is String formatted and that String is used to update
the
> >> > field,
> >> > > > :-/
> >> > > > >
> >> > > > > What is the correct way to update just one or more fields
with
> >> SolrJ?
> >> > > > >
> >> > > > >
> >> > > > > Regards,
> >> > > > >
> >> > > > > --
> >> > > > >
> >> > > > > - Luis Cappa
> >> > > > >
> >> > > > >
> >> > > >
> >> > > >
> >> > > > --
> >> > > >
> >> > > > - Luis Cappa
> >> > > >
> >> > >
> >> >
> >> >
> >> >
> >> > --
> >> >
> >> > - Luis Cappa
> >> >
> >>
> >
> >
> >
> > --
> >
> > - Luis Cappa
> >
> >
>
>
> --
>
> - Luis Cappa
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message