# Configuring a Custom Similarity

**URL:** <https://discuss.elastic.co/t/configuring-a-custom-similarity/11756>\
**Category:** Elasticsearch\
**Created:** [April 30, 2013, 8:22pm UTC](https://discuss.elastic.co/t/configuring-a-custom-similarity/11756 "2013-04-30T20:22:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [April 30, 2013, 8:22pm UTC](https://discuss.elastic.co/t/configuring-a-custom-similarity/11756/1 "2013-04-30T20:22:07Z")

</div>

I would like to port my customized Similarity class that I wrote for  
Lucene over to ElasticSearch.

Is this possible at all before 0.90.0 Beta1?  
[http://www.elasticsearch.org/guide/reference/index-modules/similarity/](http://www.elasticsearch.org/guide/reference/index-modules/similarity/)

Since "Index Modules" still don't have any page that explains where the  
example module defining documents go, can someone remind me again where  
the examples get used?

I have script with the following command that I use to create my indices  
at this time.

curl -XPOST "http://:9200$node/$indexName/?pretty=1" -d '{  
settings: {  
number\_of\_shards: 2,  
number\_of\_replicas: 3,  
analysis: {  
analyzer: {  
...  
}  
}  
}  
},  
mappings: {  
"MyDocumentType1": {  
...  
}  
}

I'm assuming (without documentation to confirm) that once I'm running  
0.90.0 I'd just add

, "similarity: {  
....  
}

Is this correct?

Can I also put the YML equivalent of this block in my elasticsearch.yml  
file?

The similarity page shows the Json document:

"similarity" : {  
"my\_similarity" : {  
"type" : "DFR",  
"basic\_model" : "g",  
"after\_effect" : "l",  
"normalization" : "h2",  
"normalization.h2.c" : "3.0"  
}  
}

Can I specify a custom class using this new 0.90.0 similarity syntax?  
Maybe

"similarity": {

```
"my_similarity": {

   "type": "com.myDomain.extensions.MySimilarity",

   "myArg1" : "foo",

   "myArg2" : "42"

 }

```

}

-Paul

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Tanguy1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tanguy1/32/1749_2.png) [@Tanguy1](https://discuss.elastic.co/u/Tanguy1)\
**Post date:** [May 2, 2013, 7:15am UTC](https://discuss.elastic.co/t/configuring-a-custom-similarity/11756/2 "2013-05-02T07:15:39Z")

</div>

Hi Paul,

I made something similar last year, and I hope this may help you:

> **[GitHub - tlrx/elasticsearch-custom-similarity-provider: A custom...](https://github.com/tlrx/elasticsearch-custom-similarity-provider)**
>
> A custom SimilarityProvider example for Elasticsearch - GitHub - tlrx/elasticsearch-custom-similarity-provider: A custom SimilarityProvider example for Elasticsearch

It was on a 0.20.0.Beta1-SNAPSHOT.

-- Tanguy

> **[tlrx - Overview](https://github.com/tlrx/)**
>
> tlrx has 23 repositories available. Follow their code on GitHub.

Twitter: @tlrx

Le mardi 30 avril 2013 22:25:16 UTC+2, P Hill a écrit :

> I would like to port my customized Similarity class that I wrote for  
> Lucene over to Elasticsearch.
> 
> Is this possible at all before 0.90.0 Beta1?  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/similarity/)
> 
> Since "Index Modules" still don't have any page that explains where the  
> example module defining documents go, can someone remind me again where  
> the examples get used?
> 
> I have script with the following command that I use to create my indices  
> at this time.
> 
> curl -XPOST "http://:9200$node/$indexName/?pretty=1" -d '{  
> settings: {  
> number\_of\_shards: 2,  
> number\_of\_replicas: 3,  
> analysis: {  
> analyzer: {  
> ...  
> }  
> }  
> }  
> },  
> mappings: {  
> "MyDocumentType1": {  
> ...  
> }  
> }
> 
> I'm assuming (without documentation to confirm) that once I'm running  
> 0.90.0 I'd just add
> 
> , "similarity: {  
> ....  
> }
> 
> Is this correct?
> 
> Can I also put the YML equivalent of this block in my elasticsearch.yml  
> file?
> 
> The similarity page shows the Json document:
> 
> "similarity" : {  
> "my\_similarity" : {  
> "type" : "DFR",  
> "basic\_model" : "g",  
> "after\_effect" : "l",  
> "normalization" : "h2",  
> "normalization.h2.c" : "3.0"  
> }  
> }
> 
> Can I specify a custom class using this new 0.90.0 similarity syntax?  
> Maybe
> 
> "similarity": {
> 
> ```
> "my_similarity": { 
> 
> "type": "com.myDomain.extensions.MySimilarity", 
> 
> "myArg1" : "foo", 
> 
> "myArg2" : "42" 
> 
> } 
> 
> ```
> 
> }
> 
> -Paul

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mathursharp](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@mathursharp](https://discuss.elastic.co/u/mathursharp)\
**Post date:** [November 15, 2013, 6:06am UTC](https://discuss.elastic.co/t/configuring-a-custom-similarity/11756/3 "2013-11-15T06:06:07Z")

</div>

Hi,

Can you please explain how to use a customsimilarity jar (created by overridding the similarity class of lucene) can be used .  
i am confused on how to use this with java api and during mapping.

please help me 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, 2:06am UTC](https://discuss.elastic.co/t/configuring-a-custom-similarity/11756/4 "2017-07-06T02:06:49Z")

</div>


