Custom IndexSearcher Implementation

(vincent arnaud) #1

Elasticsearch version (bin/elasticsearch --version) :
Version: 6.1.1, Build: bd92e7f/2017-12-17T20:23:25.338Z, JVM: 1.8.0_144

Plugin Installed :

JVM version (java -version):
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

OS version (uname -a if on a Unix-like system):
Debian 8

Description of the problem including expected versus actual behavior:

I am developping a plugin to apply a custom search function that searches based on some internal criteria.
In order to achieve this, I override the onIndexModule(IndexModule) method to add my own IndexSearcherWrapper.
My IndexSearcherWrapper overrides protected void search(List leaves, Weight weight, Collector collector) throws IOException method, but when testing, I find that this method is never called.
Am I doing something wrong or is this the same issue that has already been reported at ?

public class CustomPlugin extends Plugin implements ActionPlugin{
   public void onIndexModule(IndexModule module) {
	 module.setSearcherWrapper( indexService -> new CustomIndexSearcherWrapper(indexService));

public class CustomIndexSearcherWrapper extends IndexSearcherWrapper {
    private final IndexSettings indexSettings; 

    public CustomIndexSearcherWrapper(IndexService indexService){
	  indexSettings=  indexService.getIndexSettings();

    protected IndexSearcher wrap(IndexSearcher searcher) throws IOException {
   		final DirectoryReader directoryReader = (DirectoryReader) searcher.getIndexReader();
	    if ( directoryReader!=null) {
		   IndexSearcher indexSearcher = new CustomIndexSearcher(directoryReader);
		   return indexSearcher;
	   return searcher;

    static class CustomIndexSearcher extends IndexSearcher {
	   CustomIndexSearcher(DirectoryReader r) {
       protected void search(List<LeafReaderContext> leaves, Weight weight, Collector collector) throws IOException {
		//my own search logic but this method is never called 			

Steps to reproduce:

Provide logs (if relevant):

Thanks for your help.

(system) #2

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