我使用的是ElasticSearch的模拟实例,在这里创建它是“本地”的,这样我就不会在单元测试过程中或离开网络时依赖于运行的ES集群。例如:
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();现在,它工作得很好,我可以索引和搜索.但是,我不知道如何安装插件。我介绍了附件类型,需要安装elasticsearch-mapper-附件插件才能工作。
有什么想法吗?
发布于 2015-05-21 21:41:34
我会尝试这样做:将http://mvnrepository.com/artifact/org.elasticsearch/elasticsearch-mapper-attachments/2.5.0中的jar添加到类路径中。然后在defaultSettings中添加.put("plugin.types", org.elasticsearch.plugin.mapper.attachments.MapperAttachmentsPlugin.class.getName())。
发布于 2015-05-21 21:41:10
正如安德烈建议的那样,我补充说
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-mapper-attachments</artifactId>
<version>2.4.3</version>
</dependency>到我的pom文件(目前使用ElasticSearch 1.4.1 .)
当我加入
.put("plugin.types", org.elasticsearch.plugin.mapper.attachments.MapperAttachmentsPlugin.class.getName())它给了我错误
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)所以我把它拿走了..。再次尝试运行我的junit对模拟,它工作得很好!
https://stackoverflow.com/questions/30380986
复制相似问题