本文介绍了属性文件中的弹性搜索scala elastic4s设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从属性文件传递设置到elastic4s?以下方式有效,但在munltienvironment中不灵活:

  val settings = ImmutableSettings.settingsBuilder()。put(名称,弹性搜索)build()

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

我尝试过java配置文件elasticsearch.yaml作为java文档,但是不起作用。 >

这里有任何建议?

解决方案

您可以使用相同的方法将为Java客户端。 ImmutableSettings是一个Java Client类,不是特定于elastic4s的东西。



从类路径加载属性文件,例如,如果你在src / main / resources中有东西/com/package/settings.props

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

或者如果要从输入流加载:

  ImmutableSettings.settingsBuilder()。loadFromStream(myinputstream)

还有其他方法,只需查看 ImmutableSettings.settingsBuilder 对象。


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?

解决方案

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.

这篇关于属性文件中的弹性搜索scala elastic4s设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 05:23