AnsweredAssumed Answered

Faster Update DocumentStream based on condition

Question asked by sheetal on Dec 12, 2017
Latest reply on Dec 13, 2017 by cathy

I want to update all the documents based on a given query. I did try with OJAI java program to create a REST API. Initially, when I tried to execute a condition on non-id column, update function was very slow. For 500 records that belong to the same condition( say: CITY='NEW YORK') , it took around 16 minutes. Then I tried to build a index on CITY column. But even after indexing, it takes 4-5 minutes to execute. Is there any faster way to perform document stream updation in a faster way. Here is the sample code that I've used to update 500 records. 

@ResponseBody
@RequestMapping(value="/updatestreamquery",method=RequestMethod.GET)
public static java.lang.String updatestreamquery(@RequestParam(name="path")String path,@RequestParam(name="coname")String coname,@RequestParam(name="conval")String conval,@RequestParam(name="setname")String setname,@RequestParam(name="setvalue")String setvalue){
TABLE_PATH=path;
String s="";
QueryCondition condition= buildQueryCondition(coname,conval);
DocumentMutation document=buildDocumentMutation(setname,setvalue);
try(Table table = MapRDB.getTable(TABLE_PATH);DocumentStream documentStream =table.find(condition,"_id")){
for(Document doc:documentStream){
String s1[]=doc.toString().split(":");
s=s1[1].replaceAll("}","");
s=s.replaceAll("\"","");
table.update(s,document);

} document is a mutation object to set parameters in tabel.


}
catch(Exception e){}
return "Query update";
}

Outcomes