scala - Constructor TransportClient in class TransportClient cannot be accessed -


i wrote following class indexing documents in elasticsearch:

import java.net.inetaddress import com.typesafe.config.configfactory import org.elasticsearch.client.transport.transportclient import org.elasticsearch.common.settings.settings import org.elasticsearch.common.transport.inetsockettransportaddress import play.api.libs.json.{jsstring, jsvalue}  /**   * created liana on 12/07/16.   */ class elasticsearchconnector {    private var transportclient: transportclient = null   private val host = "localhost"   private val port = 9300   private val cluster = "elasticsearch"   private val indexname = "tests"   private val doctype = "test"    def configelasticsearch(): unit =   {     val settings = settings.settingsbuilder().put("cluster.name", cluster).build()     transportclient = new transportclient(settings)     transportclient.addtransportaddress(new inetsockettransportaddress(inetaddress.getbyname(host), port.toint))   }    def puttext(json: string, id: int): string =   {     val response = transportclient.prepareindex(indexname, doctype, id)                                   .setsource(json)                                   .get()     val responseid = response.getid     responseid   } } 

then use follows:

val json = """val jsonstring = { "title": "elastic", "price": 2000, "author":{ "first": "zachary", "last": "tong"; } }"""  val ec = new elasticsearchconnector() ec.configelasticsearch() val id = ec.puttext(json) system.out.println(id) 

this error message got:

error:(28, 23) constructor transportclient in class transportclient cannot accessed in class elasticsearchconnector transportclient = new transportclient(settings)

what wrong here?

in elasticsearch connector api transportclient class has no public constructor, 1 declared private constructor. cannot "new" instance of transportclient directly. api utilizes builder pattern heavily in order create instance of transportclient need like:

val settings = settings.settingsbuilder().put("cluster.name", cluster).build() val transportclient = transportclient.builder().settings(settings).build() transportclient.addtransportaddress(new inetsockettransportaddress(inetaddress.getbyname(host), port.toint)) 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -