Similarity plugin in ES > 6

Hi,

can someone point me how I could build a plugin that introduces a new Lucene similarity class?
So I can then call

PUT /index
{
    "settings" : {
        "index" : {
            "similarity" : {
              "dssm" : {
                "type" : "dssm",
                "model" : "intent_optimized.pb"
              }
            }
        }
    }
}
import org.apache.lucene.search.similarities.Similarity;

public class DSSM extends Similarity {
}

thanks in advance

Currently custom similarity implementations are added on a per index basis. In your plugin extend the Plugin class, and override the onIndexModule method. Then call IndexModule.addSimilarity.

@rjernst thanks for the support.
I have done a simple test working perfectly

indexModule.addSimilarity("BM25_CLONED", SimilarityService.BUILT_IN.get("BM25"));

I see that I have to set a Trifunction with parameters settings, version and scriptService. While settings seems to be accesible in plugin (actually not the same but a List of Setting ), not sure how access or generate version and scriptService.

Any direction to follow?

@rjernst I saw that it simply works.

indexModule.addSimilarity("BM25_CLONED", (settings, version, scriptService) -> createBM25Similarity(settings, version, scriptService));

Thanks a lot for the support

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