java - Updating a document in Solr using SolrJ -


i have following indexed data in solr. want add field "location" in indexed data using solrj. how can this?

"response":{"numfound":3061,"start":3059,"docs":[       {         "id":12345,         "name":"rajeev kumar",         "_version_":1223434645768768687},       {         "id":67890,         "name":"rohit kumar",         "_version_":1246457656544545434}]   }} 

after updating should -

"response":{"numfound":3061,"start":3059,"docs":[       {         "id":12345,         "name":"rajeev kumar",         "location" : <some value>,         "_version_":1223434645768768687},       {         "id":67890,         "name":"rohit kumar",         "location": <some value>,         "_version_":1246457656544545434}]   }} 

i tried -

  public static void main(string[] args) throws solrserverexception, ioexception {              string urlstring = "http://localhost:8983/solr/gettingstarted";             httpsolrclient solr = new httpsolrclient.builder(urlstring).build();             solr.setparser(new xmlresponseparser());             solrinputdocument document = new solrinputdocument();             hashmap<string, object> value = new hashmap<string, object>();              value.put("set","delhi");              document.addfield("location", value);               solr.commit();     } 

but problem creating new document instead of updating old document. in advance.

you have include id part in document values, otherwise solr isn't able find original document update. should uniquekey field.

document.addfield("id", 12345);  

you can't perform update against multiple documents in 1 request, each document has updated itself.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -