how to retrive stored scala mutable Set from ElasticSearch -
hi stroing 1 id field , 1 scala mutable set in elastic search way
var genreidset = scala.collection.mutable.set[int]() genreidset+=1 genreidset+=2 genreidset+=3 bulkrequest.add(client.prepareindex("testdb","test","123") .setsource(jsonbuilder() .startobject() .field("uuid","123") .field("genreidset",genreidset) .endobject() ) )
now want retrieve document here code
val get=client.prepareget("testdb","test","123") .setoperationthreaded(false) .setfields("uuid","genreidset") .execute() .actionget() id=get.getfield("uuid").getvalue.tostring().toint var a=get.getfield("genreidset").getvalue.tostring
and getting following output
id 123 genreidset set(1, 2, 3)
i want traverse set , store value (eg : 1 2 3) in new scala mutable set how can achieve please me new in elasticsearch , taking elasticsearch java api .please thanks
you can insert scala mutable set in elasticsearch using array method
var genreidset = scala.collection.mutable.set[int]() genreidset+=1 genreidset+=2 genreidset+=3 var xb:xcontentbuilder=xcontentfactory.jsonbuilder().startobject().field("uuid",artistimpl.getuuid) xb.startarray("getgenreidset") for(n<-genreidset) { xb.value(n) } xb.endarray() xb.endobject() val bulkrequest=client.preparebulk() bulkrequest.add(client.prepareindex("testdb","test","123") .setsource(xb) )
retrieve array , store values new scala mutable set here code
id=get.getfield("uuid").getvalue.tostring().toint var a=get.getfield("getgenreidset").getvalues.toarray() for(number<-a) { genreidset+=number.tostring().toint }
Comments
Post a Comment