ElasticSearch:在本地模拟 ES 集群上安装 elasticsearch-mapper-attachments
ElasticSearch: Install elasticsearch-mapper-attachments on a mock ES cluster locally
我在创建 ElasticSearch 的地方使用模拟实例 "locally" 这样我就不会在单元测试过程中或离线时依赖 运行 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-attachments 插件才能正常工作。
有什么想法吗?
按照 Andrei 的建议,我添加了
<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.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 对抗模拟 ES,它工作得很好!
我会尝试这样做:将 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())
.
我在创建 ElasticSearch 的地方使用模拟实例 "locally" 这样我就不会在单元测试过程中或离线时依赖 运行 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-attachments 插件才能正常工作。
有什么想法吗?
按照 Andrei 的建议,我添加了
<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.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 对抗模拟 ES,它工作得很好!
我会尝试这样做:将 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())
.