# How to use ElasticSearch Custom Similarity provider classes?

**URL:** https://discuss.elastic.co/t/how-to-use-elasticsearch-custom-similarity-provider-classes/15266
**Category:** Elasticsearch
**Created:** [January 16, 2014, 11:24am UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-custom-similarity-provider-classes/15266 "2014-01-16T11:24:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)
#### Post date: [January 16, 2014, 11:24am UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-custom-similarity-provider-classes/15266/1 "2014-01-16T11:24:02Z")

</div>

Hi,

I'm using the following two java files for overriding the Default  
Similarity of ElasticSearch 0.90.3 but it's not working for me.

> **[awnuxkjy/es-custom-similarity-provider](https://github.com/awnuxkjy/es-custom-similarity-provider/tree/master/src/main/java/org/elasticsearch/index/similarity)**
>
> es-custom-similarity-provider - elasticsearch similarity Custom plug-in

I have complied the two java files and added the corresponding class files  
in my /lib/elasticsearc-0.90.3.jar file in the path  
org/elasticsearch/index/similarity. Now, I'm trying to use those files in  
my mapping like mentioned in:-

curl -XPOST '[http://host](http://host):port/tweeter/' -d '  
{  
"settings": {  
"similarity": {  
"index": {  
"type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"  
},  
"search": {  
"type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"  
}  
}  
}  
}'

But it's giving me following error:-

{"error":"IndexCreationException[[acqindex] failed to create index]; nested: ElasticSearchIllegalArgumentException[SimilarityProvider [my\_similarity] must have an associated type]; ","status":400}

Can anyone please tell me how can I use these two files for overriding the default similarity ?

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/86099655-b887-42a8-92e4-92fa1f06ce48%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/86099655-b887-42a8-92e4-92fa1f06ce48%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)
#### Post date: [January 16, 2014, 4:13pm UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-custom-similarity-provider-classes/15266/2 "2014-01-16T16:13:04Z")

</div>

I solved the error problem but still Elasticsearch is using its Default  
Similariy. Can anyone tell me why is it not taking these new  
CustomSimilarity files into consideration.  
On Thursday, 16 January 2014 16:54:02 UTC+5:30, coder wrote:

> Hi,
> 
> I'm using the following two java files for overriding the Default  
> Similarity of Elasticsearch 0.90.3 but it's not working for me.
> 
> [https://github.com/awnuxkjy/es-custom-similarity-provider/tree/master/src/main/java/org/elasticsearch/index/similarity](https://github.com/awnuxkjy/es-custom-similarity-provider/tree/master/src/main/java/org/elasticsearch/index/similarity)
> 
> I have complied the two java files and added the corresponding class files  
> in my /lib/elasticsearc-0.90.3.jar file in the path  
> org/elasticsearch/index/similarity. Now, I'm trying to use those files in  
> my mapping like mentioned in:-
> 
> curl -XPOST '[http://host](http://host):port/tweeter/' -d '  
> {  
> "settings": {  
> "similarity": {  
> "index": {  
> "type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"  
> },  
> "search": {  
> "type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"  
> }  
> }  
> }  
> }'
> 
> But it's giving me following error:-
> 
> {"error":"IndexCreationException[[acqindex] failed to create index]; nested: ElasticSearchIllegalArgumentException[SimilarityProvider [my\_similarity] must have an associated type]; ","status":400}
> 
> Can anyone please tell me how can I use these two files for overriding the default similarity ?
> 
> Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e082c7b9-9c7d-4b67-94e5-7194fcf2b114%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e082c7b9-9c7d-4b67-94e5-7194fcf2b114%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)
#### Post date: [January 16, 2014, 5:52pm UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-custom-similarity-provider-classes/15266/3 "2014-01-16T17:52:43Z")

</div>

I am assuming that you packaged the two Java files into a jar file and  
deploy it to the $ES\_PATH lib directory. Elasticsearch will pick up any jar  
files in that directory.

Similarities are either set to be the default for all the indices via the  
index.similarity.default.type configuration parameter [1] or it must be  
associated directly with a field [2]. Use the example from the website,  
your mapping would look something like:

{  
"book" : {  
"properties" : {  
"title" : { "type" : "string", "similarity" : "index" }  
}  
}

As stated in the other thread, I believe the example provided in the plugin  
is misleading since there is no individual index/search similarity. The  
example creates two similarities types, "index" and "search", which use the  
same similarity type.

[1]

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

[2]

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Cheers,

Ivan

On Thu, Jan 16, 2014 at 8:13 AM, coder [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:

> I solved the error problem but still Elasticsearch is using its Default  
> Similariy. Can anyone tell me why is it not taking these new  
> CustomSimilarity files into consideration.
> 
> On Thursday, 16 January 2014 16:54:02 UTC+5:30, coder wrote:
> 
> > Hi,
> > 
> > I'm using the following two java files for overriding the Default  
> > Similarity of Elasticsearch 0.90.3 but it's not working for me.
> > 
> > [GitHub - awnuxkjy/es-custom-similarity-provider: elasticsearch similarity Custom plug-in](https://github.com/awnuxkjy/es-custom-similarity-provider/)  
> > tree/master/src/main/java/org/elasticsearch/index/similarity
> > 
> > I have complied the two java files and added the corresponding class  
> > files in my /lib/elasticsearc-0.90.3.jar file in the path  
> > org/elasticsearch/index/similarity. Now, I'm trying to use those files  
> > in my mapping like mentioned in:-
> > 
> > curl -XPOST '[http://host](http://host):port/tweeter/' -d '  
> > {  
> > "settings": {  
> > "similarity": {  
> > "index": {  
> > "type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"  
> > },  
> > "search": {  
> > "type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"  
> > }  
> > }  
> > }  
> > }'
> > 
> > But it's giving me following error:-
> > 
> > {"error":"IndexCreationException[[acqindex] failed to create index]; nested: ElasticSearchIllegalArgumentException[SimilarityProvider [my\_similarity] must have an associated type]; ","status":400}
> > 
> > Can anyone please tell me how can I use these two files for overriding the default similarity ?
> > 
> > Thanks
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/e082c7b9-9c7d-4b67-94e5-7194fcf2b114%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e082c7b9-9c7d-4b67-94e5-7194fcf2b114%40googlegroups.com)  
> > .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA037LOhM2ipiTVj39mm84M1YipVyjAJSFrnrYH9tYb8w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA037LOhM2ipiTVj39mm84M1YipVyjAJSFrnrYH9tYb8w%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)
#### Post date: [January 17, 2014, 7:14am UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-custom-similarity-provider-classes/15266/4 "2014-01-17T07:14:57Z")

</div>

Thanks a lot. It really solved my problem.

On Thu, Jan 16, 2014 at 11:22 PM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> I am assuming that you packaged the two Java files into a jar file and  
> deploy it to the $ES\_PATH lib directory. Elasticsearch will pick up any jar  
> files in that directory.
> 
> Similarities are either set to be the default for all the indices via the  
> index.similarity.default.type configuration parameter [1] or it must be  
> associated directly with a field [2]. Use the example from the website,  
> your mapping would look something like:
> 
> {  
> "book" : {  
> "properties" : {  
> "title" : { "type" : "string", "similarity" : "index" }  
> }  
> }
> 
> As stated in the other thread, I believe the example provided in the  
> plugin is misleading since there is no individual index/search similarity.  
> The example creates two similarities types, "index" and "search", which use  
> the same similarity type.
> 
> [1]  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-similarity.html)  
> [2]  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#_configuring_similarity_per_field)
> 
> Cheers,
> 
> Ivan
> 
> On Thu, Jan 16, 2014 at 8:13 AM, coder [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:
> 
> > I solved the error problem but still Elasticsearch is using its Default  
> > Similariy. Can anyone tell me why is it not taking these new  
> > CustomSimilarity files into consideration.
> > 
> > On Thursday, 16 January 2014 16:54:02 UTC+5:30, coder wrote:
> > 
> > > Hi,
> > > 
> > > I'm using the following two java files for overriding the Default  
> > > Similarity of Elasticsearch 0.90.3 but it's not working for me.
> > > 
> > > [GitHub - awnuxkjy/es-custom-similarity-provider: elasticsearch similarity Custom plug-in](https://github.com/awnuxkjy/es-custom-similarity-provider/)  
> > > tree/master/src/main/java/org/elasticsearch/index/similarity
> > > 
> > > I have complied the two java files and added the corresponding class  
> > > files in my /lib/elasticsearc-0.90.3.jar file in the path  
> > > org/elasticsearch/index/similarity. Now, I'm trying to use those files  
> > > in my mapping like mentioned in:-
> > > 
> > > curl -XPOST '[http://host](http://host):port/tweeter/' -d '  
> > > {  
> > > "settings": {  
> > > "similarity": {  
> > > "index": {  
> > > "type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"  
> > > },  
> > > "search": {  
> > > "type": "org.elasticsearch.index.similarity.CustomSimilarityProvider"  
> > > }  
> > > }  
> > > }  
> > > }'
> > > 
> > > But it's giving me following error:-
> > > 
> > > {"error":"IndexCreationException[[acqindex] failed to create index]; nested: ElasticSearchIllegalArgumentException[SimilarityProvider [my\_similarity] must have an associated type]; ","status":400}
> > > 
> > > Can anyone please tell me how can I use these two files for overriding the default similarity ?
> > > 
> > > Thanks
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/e082c7b9-9c7d-4b67-94e5-7194fcf2b114%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e082c7b9-9c7d-4b67-94e5-7194fcf2b114%40googlegroups.com)  
> > > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA037LOhM2ipiTVj39mm84M1YipVyjAJSFrnrYH9tYb8w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQA037LOhM2ipiTVj39mm84M1YipVyjAJSFrnrYH9tYb8w%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp7USq9Z7j%2BcPVEmK3u%3DxUMfqkBMLx\_-ZOuaJDy2YjnFGA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp7USq9Z7j%2BcPVEmK3u%3DxUMfqkBMLx_-ZOuaJDy2YjnFGA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [July 6, 2017, 1:56am UTC](https://discuss.elastic.co/t/how-to-use-elasticsearch-custom-similarity-provider-classes/15266/5 "2017-07-06T01:56:15Z")

</div>


