I have a percolation index with a custom similarity (to ignore idf) and a mapping to use this custom similarity:

{
  "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:

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

I get a result that includes this:

{
  "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?