Elasticsearch scala elastic4s settings from property file

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 06:43:09

问题


is there a way how to pass settings to elastic4s from property file? The following way works but it is not flexible in munltienvironment:

 val settings = ImmutableSettings.settingsBuilder().put("cluster.name","elasticsearch").build()

 val client = ElasticClient.remote(settings, "154.86.209.242" -> 9300, "153.89.219.241" -> 9300)

I tried java configuration file elasticsearch.yaml as mantioned in java doc but that doesn't work.

Any suggestion here?


回答1:


You can do this using the same method you would for the Java client. The ImmutableSettings is a Java Client class not something that is specific to elastic4s.

To load your properties file from the classpath, eg if you have something in src/main/resources/com/package/settings.props

ImmutableSettings.settingsBuilder().loadFromClasspath("/com/package/mysettings.yaml")

Or if you want to load from an input stream:

ImmutableSettings.settingsBuilder().loadFromStream(myinputstream)

There are other methods too, just check out the ImmutableSettings.settingsBuilder object.



来源:https://stackoverflow.com/questions/26868602/elasticsearch-scala-elastic4s-settings-from-property-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!