I am using DirectXmlRequest to index XML. This is just a test case as
my client would be sending me a SOLR compliant XML. so I was trying to
simulate it by reading a doc from an exiting core and reindexing it.

                HttpSolrServer server = new
HttpSolrServer("http://testsolr:8080/solr/mycore";);
                QueryResponse resp = server.query(new 
SolrQuery("contentid:(1184911
OR 1182684)"));
                SolrDocumentList list = resp.getResults();
                if(list != null && !list.isEmpty()) {
                        for(SolrDocument doc : list) {
                                SolrInputDocument iDoc = 
ClientUtils.toSolrInputDocument(doc);                          
                                String contentid = (String) 
iDoc.getFieldValue("egcontentid");
                                String name = (String) 
iDoc.getFieldValue("name");
                                iDoc.setField("name", DigestUtils.md5Hex(name));
                                
                                String xml = ClientUtils.toXML(iDoc);           
                
                                DirectXmlRequest up = new 
DirectXmlRequest("/update",
"<add>"+xml+"</add>");
                                server.request(up);
                                server.commit();
                                
                                System.out.println("Updated name in contentid - 
" + contentid);
                                
                        }
                }

Ravi Kiran

On Wed, Oct 10, 2012 at 1:02 PM, Gopal Patwa <gopalpa...@gmail.com> wrote:
> Instead addfield method use setfield
> On Oct 10, 2012 9:54 AM, "Ravi Solr" <ravis...@gmail.com> wrote:
>
>> Gopal I did in fact test the same and it worked when I delete ted the
>> geolocation_0_coordinate and geolocation_1_coordinate. But that seems
>> weird, so I was thinking if there is something else I need to do to
>> avoid doing this awkward workaround.
>>
>> Ravi Kiran Bhaskar
>>
>> On Wed, Oct 10, 2012 at 12:36 PM, Gopal Patwa <gopalpa...@gmail.com>
>> wrote:
>> > You need remove field after read solr doc,  when u add new field it will
>> > add to list,  so when u try to commit the update field,  it will be multi
>> > value and in your schema it is single value
>> > On Oct 10, 2012 9:26 AM, "Ravi Solr" <ravis...@gmail.com> wrote:
>> >
>> >> Hello,
>> >>         I have a weird problem, Whenever I read the doc from solr and
>> >> then index the same doc that already exists in the index (aka
>> >> reindexing) I get the following error. Can somebody tell me what I am
>> >> doing wrong. I use solr 3.6 and the definition of the field is given
>> >> below
>> >>
>> >> <fieldType name="latlong" class="solr.LatLonType"
>> >> subFieldSuffix="_coordinate"/>
>> >> <dynamicField name="*_coordinate" type="tdouble" indexed="true"
>> >> stored="true"/>
>> >>
>> >> Exception in thread "main"
>> >> org.apache.solr.client.solrj.SolrServerException: Server at
>> >> http://testsolr:8080/solr/mycore returned non ok status:400,
>> >> message:ERROR: [doc=1182684] multiple values encountered for non
>> >> multiValued field geolocation_0_coordinate: [39.017608, 39.017608]
>> >>         at
>> >>
>> org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:328)
>> >>         at
>> >>
>> org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:211)
>> >>         at com.wpost.search.indexing.MyTest.main(MyTest.java:31)
>> >>
>> >>
>> >> The data in the index looks as follows
>> >>
>> >> <str name="geolocation">39.017608,-77.375239</str>
>> >> <arr name="geolocation_0_coordinate">
>> >>      <double>39.017608</double>
>> >>      <double>39.017608</double>
>> >> </arr>
>> >> <arr name="geolocation_1_coordinate">
>> >>     <double>-77.375239</double>
>> >>     <double>-77.375239</double>
>> >> </arr>
>> >>
>> >> Thanks
>> >>
>> >> Ravi Kiran Bhaskar
>> >>
>>

Reply via email to