krinker
krinker

Reputation: 1092

ElasticSearch: Install elasticsearch-mapper-attachments on a mock ES cluster locally

I am using mock instance of ElasticSearch where I create it "locally" so that I won't be dependent on a running ES cluster during my unit test process or when I am off network. For example:

Settings defaultSettings = ImmutableSettings
        .settingsBuilder()
        .put(ElasticSearchReservedWords.CLUSTER_NAME.getText(), "test-cluster-" + NetworkUtils.getLocalAddress().getHostName())
        .put(ElasticSearchReservedWords.PATH_DATA.getText(), new File("C:/Temp/mock_elasticsearch_cluster/data").getAbsolutePath())
        .put(ElasticSearchReservedWords.PATH_WORK.getText(), new File("C:/Temp/mock_elasticsearch_cluster/work").getAbsolutePath())
        .put(ElasticSearchReservedWords.PATH_LOG.getText(), new File("C:/Temp/mock_elasticsearch_cluster/log").getAbsolutePath())
        .put(ElasticSearchReservedWords.PATH_CONF.getText(), new File("config").getAbsolutePath())
        .put("index.store.type", "memory")
        .build();

String settingsSource = getClass().getName().replace('.', '/') + ".yml";
Settings finalSettings = settingsBuilder()
            .loadFromClasspath(settingsSource)
            .put(defaultSettings)
            .put(settings)
            .put("name", id)
            .build();
Node node = nodeBuilder()
               .settings(finalSettings)
               .build();

Now, it works great and I am able to index and search... However, I can not figure out how to install plugins. I introduced attachment type and need to install elasticsearch-mapper-attachments plugin in order for it to work.

Any ideas?

Upvotes: 1

Views: 743

Answers (2)

Andrei Stefan
Andrei Stefan

Reputation: 52368

I would try this: add the jar from http://mvnrepository.com/artifact/org.elasticsearch/elasticsearch-mapper-attachments/2.5.0 to your classpath. Then in the defaultSettings I would add .put("plugin.types", org.elasticsearch.plugin.mapper.attachments.MapperAttachmentsPlugin.class.getNam‌​e()).

Upvotes: 0

krinker
krinker

Reputation: 1092

As Andrei suggested, I added

<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch-mapper-attachments</artifactId>
    <version>2.4.3</version>
</dependency>

to my pom file (using ElasticSearch 1.4.1 at the moment...)

When I added

.put("plugin.types", org.elasticsearch.plugin.mapper.attachments.MapperAttachmentsPlugin.class.getNam‌​e())

It gave me error

1) A binding to org.elasticsearch.index.mapper.attachment.RegisterAttachmentType was already configured at org.elasticsearch.plugin.mapper.attachments.AttachmentsIndexModule.configure(AttachmentsIndexModule.java:32).
  at org.elasticsearch.plugin.mapper.attachments.AttachmentsIndexModule.configure(AttachmentsIndexModule.java:32)

1 error
    at org.elasticsearch.common.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:344)
    at org.elasticsearch.common.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:151)
    at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:102)
    at org.elasticsearch.common.inject.InjectorImpl.createChildInjector(InjectorImpl.java:131)
    at org.elasticsearch.common.inject.ModulesBuilder.createChildInjector(ModulesBuilder.java:69)
    at org.elasticsearch.indices.InternalIndicesService.createIndex(InternalIndicesService.java:299)
    at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$2.execute(MetaDataCreateIndexService.java:382)
    at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:329)
    at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:153)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

So I removed it... tried again to run my junit against mock ES and it worked just fine!

Upvotes: 1

Related Questions