Elasticsearch score disable IDF

2019-03-16 00:14发布

问题:

I'm using ES for searching a huge list of human names employing fuzzy search techniques.

TF is applicable for scoring, but IDF is really not required for me in this case. This is really diluting the score. I still want TF and Field Norm to be applied to the score.

How do I disable/suppress IDF for my queries, but keep TF and Field Norm?

I came across the Disable IDF calculation thread, but it did not help me. It also seems like the constant score query would not help me in this case.

回答1:

When create index, we can put our own similarity calculate method into the setting parts, if you need only disable IDF and use others as the default setting, you can write just a simple script such as:

"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;"`}

This is shown here.