# Custom Similarity Not Respected In Percolate Query

**URL:** <https://discuss.elastic.co/t/custom-similarity-not-respected-in-percolate-query/239541>\
**Category:** Elasticsearch\
**Created:** [July 1, 2020, 8:06pm UTC](https://discuss.elastic.co/t/custom-similarity-not-respected-in-percolate-query/239541 "2020-07-01T20:06:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vp\_tech](https://avatars.discourse-cdn.com/v4/letter/v/47e85d/32.png) [@vp\_tech](https://discuss.elastic.co/u/vp_tech)\
**Post date:** [July 1, 2020, 8:06pm UTC](https://discuss.elastic.co/t/custom-similarity-not-respected-in-percolate-query/239541/1 "2020-07-01T20:06:07Z")

</div>

I have a percolation index with a custom similarity (to ignore idf) 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": ...
        }
      ]
    }
  }
}

```

I get a result that includes 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": []
    }
  ]
}

```

So it is still obviously using idf and additionally it is claiming to use both submitted documents from the query in the calculation even though the Elasticsearch docs specifically state in reference to percolation: "This in-memory index can just hold this one document and it is optimized for that."

So, is there something I'm doing wrong in order to get my percolator to use the specified similarity?

---

<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 29, 2020, 8:06pm UTC](https://discuss.elastic.co/t/custom-similarity-not-respected-in-percolate-query/239541/2 "2020-07-29T20:06:42Z")

</div>

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