# Override class for plugin in ElasticSearch

**URL:** https://discuss.elastic.co/t/override-class-for-plugin-in-elasticsearch/121672
**Category:** Elasticsearch
**Created:** [February 27, 2018, 2:04pm UTC](https://discuss.elastic.co/t/override-class-for-plugin-in-elasticsearch/121672 "2018-02-27T14:04:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![iKishanSojitra](https://avatars.discourse-cdn.com/v4/letter/i/258eb7/32.png) [@iKishanSojitra](https://discuss.elastic.co/u/iKishanSojitra)
#### Post date: [February 27, 2018, 2:04pm UTC](https://discuss.elastic.co/t/override-class-for-plugin-in-elasticsearch/121672/1 "2018-02-27T14:04:56Z")

</div>

I'm working on ElasticSearch Plugin to retrieve total frequency of searched term. I've already created maven project and successfully deployed my test plugin into ElasticSearch but I have no idea how to write override function to perform this task.

I have found out that there is a [getTotalTermFreq()](https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.2.2/org/elasticsearch/index/similarity/ScriptedSimilarity.Term.html#getTotalTermFreq--) function in `org.elasticsearch.index.similarity.ScriptedSimilarity.Term` class/object which returns the total number of occurrences of this term in the index, or -1 if this statistic is not available. But, I have no idea how to use this function in plugin!

I already tried looking in to other open source plugins available on github but couldn't find anything useful or I can say I didn't understand that much because of my no-experience in Java.

Can someone please help?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [February 27, 2018, 8:44pm UTC](https://discuss.elastic.co/t/override-class-for-plugin-in-elasticsearch/121672/2 "2018-02-27T20:44:47Z")

</div>

It sounds like you want to implement your own Similarity. Try looking at [Plugin.onIndexModule](https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/plugins/Plugin.java#L149) and then add a SimilarityProvider.

---

<div class="post-metadata">

### Author: ![iKishanSojitra](https://avatars.discourse-cdn.com/v4/letter/i/258eb7/32.png) [@iKishanSojitra](https://discuss.elastic.co/u/iKishanSojitra)
#### Post date: [February 28, 2018, 9:40am UTC](https://discuss.elastic.co/t/override-class-for-plugin-in-elasticsearch/121672/3 "2018-02-28T09:40:03Z")

</div>

@rjernst  
Thank you so much for your response and time.

I'm sorry, I can not understand how `Plugin.onIndexModule` is useful in this case as I want to retrieve term count when we execute a search query.

I'm very confused about all this!!! I want to implement this asap because I have a conference with about this feature on Friday. So, If it is not too much to ask and doesn't bother you, can you please write only a override class with `long` function which returns the term count in index? It would be very helpful for me!

Thanks,  
Kishan

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 28, 2018, 9:40am UTC](https://discuss.elastic.co/t/override-class-for-plugin-in-elasticsearch/121672/4 "2018-03-28T09:40:12Z")

</div>

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