How to add custom similarity provider to ES v2.3?

I want to implement my custom similarity function based on TFIDF with the codes forked from this repo.

With service elasticsearch restart, the log prints out:

[2016-12-07 12:29:10,350][DEBUG][action.admin.indices.create] [node-chito] [test1] failed to create
[test1] IndexCreationException[failed to create index]; nested: IllegalArgumentException[Unknown Similarity type [org.elasticsearch.index.similarity.CustomSimilarityProvider] for [index]];
    at org.elasticsearch.indices.IndicesService.createIndex(IndicesService.java:362)
    at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:309)
    at org.elasticsearch.cluster.ClusterStateUpdateTask.execute(ClusterStateUpdateTask.java:45)
    at org.elasticsearch.cluster.service.InternalClusterService.runTasksForExecutor(InternalClusterService.java:468)
    at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:772)
    at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:231)
    at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:194)
    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)
Caused by: java.lang.IllegalArgumentException: Unknown Similarity type [org.elasticsearch.index.similarity.CustomSimilarityProvider] for [index]
    at org.elasticsearch.index.similarity.SimilarityModule.configure(SimilarityModule.java:82)
    at org.elasticsearch.common.inject.AbstractModule.configure(AbstractModule.java:60)
    at org.elasticsearch.common.inject.spi.Elements$RecordingBinder.install(Elements.java:233)
    at org.elasticsearch.common.inject.spi.Elements.getElements(Elements.java:105)
    at org.elasticsearch.common.inject.InjectorShell$Builder.build(InjectorShell.java:143)
    at org.elasticsearch.common.inject.InjectorBuilder.build(InjectorBuilder.java:99)
    at org.elasticsearch.common.inject.InjectorImpl.createChildInjector(InjectorImpl.java:157)
    at org.elasticsearch.common.inject.ModulesBuilder.createChildInjector(ModulesBuilder.java:55)
    at org.elasticsearch.indices.IndicesService.createIndex(IndicesService.java:358)
    ... 9 more

I'm wondering if I can add custom similarity provider like ES v1.x since SimilarityModule.configure() differs between v1.3 and v2.3.
Also on ES v5.x there's only SimilarityService.java instead of SimilarityModule.java.

How to add custom similarity prodvider for ES v2.x and v5.x?
Is it possible to add it by using plugin?
Or maybe I misunderstand something?

Thank you in advance.

I have an example and description at https://github.com/sdauletau/elasticsearch-position-similarity/blob/master/Advanced%20Scoring%20with%20Elasticsearch%20Similarity%20Plugins.md.

Thank you, I've already turned to use plugin to implement custom similarity function.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.