Custom IndexSearcher Implementation

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

Plugin Installed :
None

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:

Hi,
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 https://github.com/elastic/elasticsearch/issues/30758 ?

public class CustomPlugin extends Plugin implements ActionPlugin{
   @Override
   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();
    }

    @Override
    protected IndexSearcher wrap(IndexSearcher searcher) throws IOException {
   		final DirectoryReader directoryReader = (DirectoryReader) searcher.getIndexReader();
	    if ( directoryReader!=null) {
		   IndexSearcher indexSearcher = new CustomIndexSearcher(directoryReader);
		   indexSearcher.setQueryCache(indexSearcher.getQueryCache());
		   indexSearcher.setQueryCachingPolicy(indexSearcher.getQueryCachingPolicy());
		   indexSearcher.setSimilarity(indexSearcher.getSimilarity(true));
		   return indexSearcher;
	    }
	   return searcher;
	 }

    static class CustomIndexSearcher extends IndexSearcher {
	   CustomIndexSearcher(DirectoryReader r) {
         super(r);
       }
	
	   @Override
       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:
None

Provide logs (if relevant):
None

Thanks for your help.

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