# Custom Similarity for Percolate Query

**URL:** <https://discuss.elastic.co/t/custom-similarity-for-percolate-query/315654>\
**Category:** Elasticsearch\
**Created:** [October 3, 2022, 5:37am UTC](https://discuss.elastic.co/t/custom-similarity-for-percolate-query/315654 "2022-10-03T05:37:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aneeshkoya](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@aneeshkoya](https://discuss.elastic.co/u/aneeshkoya)\
**Post date:** [October 3, 2022, 5:37am UTC](https://discuss.elastic.co/t/custom-similarity-for-percolate-query/315654/1 "2022-10-03T05:37:12Z")

</div>

I created a percolation index with a custom similarity in its settings and a mapping to use this custom similarity:

```auto
{
  "my-index": {
    "settings": {
      "index": {
        "similarity": {
          "idfless": {
            "type": "scripted",
            "script": {
              "source": "double tf = Math.sqrt(doc.freq); double idf = 1.0; double norm = 1/Math.sqrt(doc.length); return query.boost * tf * idf * norm;"
            }
          }
        }
      }
    },
    "mappings": {
      "my-doc-type": {
        "message": {
          "type": "text",
          "similarity": "idfless"
        },
        "query": {
          "type": "percolator"
        }
      }
    }

```

However, this similarity setting is not respected. If I run a query and ask it to be explained like:

```auto
POST my-index/search/0/_explain
{
  "query": {
    percolate" : {
      "field" : "query",
      "documents" : [
        {
          "message": ...
        },
        {
          "message": ...
        }
      ]
    }
  }
}

```

However, result obtained is like this:

```auto
{
  "value": 0.6931472,
  "description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
  "details": [
    {
      "value": 1,
      "description": "docFreq",
      "details": []
    },
    {
      "value": 2,
      "description": "docCount",
      "details": []
    }
  ]
}

```

Is there something wrong that I'm doing in order to get my percolator to use the specified similarity? Similar question has been posted in [https://discuss.elastic.co/t/custom-similarity-not-respected-in-percolate-query/239541](https://discuss.elastic.co/t/custom-similarity-not-respected-in-percolate-query/239541), however it is not answered yet.

---

<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:** [October 31, 2022, 5:38am UTC](https://discuss.elastic.co/t/custom-similarity-for-percolate-query/315654/2 "2022-10-31T05:38:06Z")

</div>

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