Pergunta

created a wrapper for elastic search. it working fine while running as java application. But while i create OSGI bundle it throwing a error.

  org.elasticsearch.env.FailedToResolveConfigException: Failed to resolve config path [names.txt], tried file path [names.txt], path file [/home/local/PAYODA/sidharthan.r/config/names.txt], and classpath
at org.elasticsearch.env.Environment.resolveConfig(Environment.java:207)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareSettings(InternalSettingsPreparer.java:118)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:154)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:120)
at com.payoda.commons.elasticsearch.util.GenericEsSearch.getES(GenericEsSearch.java:54)

Pls help me.. am using ES version 0.90.10

Foi útil?

Solução 2

Place names.txt file inside bundle.you can find names.txt file inside elasticsearch.jar.Add following code where you create client instance.

        Thread.currentThread().setContextClassLoader(*classname*.class.getClassLoader());
        Builder settings = ImmutableSettings.settingsBuilder().put("cluster.name", esHosts);
        settings.put("path.conf", path_of_names.txt);
        TransportClient transportClient = new TransportClient(settings);

I added 2 jars to my class_path, they are elasticsearch.jar,lucene.jar. Version of jars must be same as version of Elasticsearch.

now it works like charm..

Outras dicas

As you can see in the implementation of Environment.resolveConfig() (the one that throws the Exception), it uses settings.getClassLoader().getResource(path) to resolve files. The default is to use Classes.getDefaultClassLoader() which uses Thread.getContextClassLoader(). As 'names.txt' is inside elasticsearch*.jar, any ClassLoader from an org.elasticsearch.* class will do:

Settings settings = ImmutableSettings.settingsBuilder()
  .classLoader(Settings.class.getClassLoader())
  // snip: add some settings
  .build();

Alternatively, you can place your own names.txt file either in the current working directory or in your config directory ('path.conf' setting or $home/config by default, $home being the value of 'path.home' setting or 'user.dir' system property by default).

Btw, I've done some experimenting with elasticsearch and OSGI myself, so maybe molindo-elasticsync is of help. Additionally, there are elasticsearch bundles provided by Servicemix that might be helpful.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top