Reputation: 53
I have ID(unique key) and URL fields in my indexed document. They have same values. And I am able to update the URL field(changing the DNS) as following:
{"id":"ABC.com/content/dam/images/infographics/Infographic_Final.pdf","url":{"set":"XYZ.com/content/dam/images/infographics/Infographic_Final.pdf"}}
what i am trying to achieve is i have 1000 documents having field ID starting with ABC.com. It should update URL field with XYZ.com and the rest of the URL-path must remain the same. can i achieve this? i dont want to update URL repeatedly for 1000 times.
Thanks in advance.
Upvotes: 0
Views: 456
Reputation: 53
I was able to achieve it using Java program. I used Solr-query to find all ID starting with ABC.com. I got URL corresponding to that ID and replaced ABC.com with XYZ.com and kept the rest of the path same. Used set command and updated all the URLs(only URL field) using while loop.
String urlString = "http://localhost:8090/solr/collectionName";
SolrClient solrClient = new HttpSolrClient.Builder(urlString).build();
SolrQuery query=new SolrQuery();
query.setQuery("id:*ABC*");
query.setRows(2147483647);
QueryRequest req = new QueryRequest(query);
QueryResponse response = req.process(solrClient);
SolrDocumentList docList=response.getResults();
Iterator <SolrDocument> itr=docList.iterator();
String IdValue="";
Map<String, String> cmd1;
Map<String, String> cmd2;
UpdateRequest ureq=new UpdateRequest();
while(itr.hasNext()){
JSONObject resultItems = new JSONObject();
SolrDocument doc= itr.next();
IdValue=(String)doc.getFieldValue("id");
SolrInputDocument newdoc = new SolrInputDocument();
cmd1 = new HashMap<String, String>();
String URL=IdValue.replace("www.ABC.com", "www.XYZ.com");
cmd1.put("set", URL);
newdoc.addField("id", IdValue);
newdoc.addField("url", cmd1);
ureq.add(newdoc);
cmd1=null;
cmd2=null;
}
NamedList res = solrClient.request(ureq);
System.out.println(" response "+res);
solrClient.commit();
solrClient.close();
Upvotes: 1
Reputation: 15789
if you are asking for a 'bulk update' like SQL's 'UPDATE table WHERE...' that is not possible in Solr. You have to submit each doc (mind you, you can submit many docs in one request, but all doc's info must be in there).
Upvotes: 1