# How to complete disable TF-IDF?

**URL:** <https://discuss.elastic.co/t/how-to-complete-disable-tf-idf/70570>\
**Category:** Elasticsearch\
**Created:** [January 4, 2017, 3:19pm UTC](https://discuss.elastic.co/t/how-to-complete-disable-tf-idf/70570 "2017-01-04T15:19:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Sudakov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_sudakov/32/13893_2.png) [@Alex\_Sudakov](https://discuss.elastic.co/u/Alex_Sudakov)\
**Post date:** [January 4, 2017, 3:19pm UTC](https://discuss.elastic.co/t/how-to-complete-disable-tf-idf/70570/1 "2017-01-04T15:19:06Z")

</div>

Hello community, how to complete disable TF-IDF? and replace it by best match.  
We use ES for music identification, thanks.

---

<div class="post-metadata">

**Author:** ![sdauletau](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sdauletau/32/24779_2.png) [@sdauletau](https://discuss.elastic.co/u/sdauletau)\
**Post date:** [January 4, 2017, 6:01pm UTC](https://discuss.elastic.co/t/how-to-complete-disable-tf-idf/70570/2 "2017-01-04T18:01:22Z")

</div>

Take a look at function score query. You can override TF-IDF score by combining boost and weight.  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)

You can also implement custom similarity in a plugin.

> **[sdauletau/elasticsearch-simple-similarity](https://github.com/sdauletau/elasticsearch-simple-similarity)**
>
> elasticsearch-simple-similarity - Elasticsearch "ignore tf-idf" plugin

> <https://github.com/sdauletau/elasticsearch-position-similarity/blob/master/Advanced%20Scoring%20with%20Elasticsearch%20Similarity%20Plugins.md>

---

<div class="post-metadata">

**Author:** ![Alex\_Sudakov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alex_sudakov/32/13893_2.png) [@Alex\_Sudakov](https://discuss.elastic.co/u/Alex_Sudakov)\
**Post date:** [January 8, 2017, 9:06pm UTC](https://discuss.elastic.co/t/how-to-complete-disable-tf-idf/70570/3 "2017-01-08T21:06:08Z")

</div>

Hello Sergei, since ES 5.1 site plugin is disabled 😞  
Exist any other less painful way to do it?

---

<div class="post-metadata">

**Author:** ![sdauletau](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sdauletau/32/24779_2.png) [@sdauletau](https://discuss.elastic.co/u/sdauletau)\
**Post date:** [January 9, 2017, 7:49pm UTC](https://discuss.elastic.co/t/how-to-complete-disable-tf-idf/70570/4 "2017-01-09T19:49:56Z")

</div>

As I said, take a look at function score query. It allows to replace internal score.

```
curl -s -XDELETE "http://localhost:9200/test_index"

curl -s -XPUT "http://localhost:9200/test_index" -d '
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0,
      "similarity": {
        "default": {
          "type": "classic"
        }
      }
    }
  }
}
'

curl -XPUT 'localhost:9200/test_index/test_type/_mapping' -d '
{
  "test_type": {
    "properties": {
      "field1": {
        "type": "text"
      },
      "field2": {
        "type": "text"
      }
    }
  }
}
'

curl -s -XPUT "localhost:9200/test_index/test_type/1" -d '
{"field1" : "bar foo", "field2" : "bar"}
'

curl -s -XPUT "localhost:9200/test_index/test_type/2" -d '
{"field1" : "bar bar bar", "field2" : "foo foo foo"}
'

curl -s -XPUT "localhost:9200/test_index/test_type/3" -d '
{"field1" : "bar bar foo foo", "field2" : "bar bar foo foo"}
'

curl -s -XPOST "http://localhost:9200/test_index/_refresh"

echo
echo
echo 'expecting doc 3 to have score 7.0'

curl -s "localhost:9200/test_index/test_type/_search?pretty=true" -d '
{
  "explain": false,
  "query": {
    "bool": {
      "disable_coord": true,
      "should": [
        {
          "function_score": {
            "boost": "1.0",
            "weight": "2.0",
            "boost_mode": "replace",
            "query": {
              "bool": {
                "filter": {
                  "match": {
                    "field1": {
                      "query": "foo"
                    }
                  }
                }
              }
            }
          }
        },
        {
          "function_score": {
            "boost": "1.0",
            "weight": "5.0",
            "boost_mode": "replace",
            "query": {
              "bool": {
                "filter": {
                  "match": {
                    "field2": {
                      "query": "foo"
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}
'
```

---

<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:** [February 6, 2017, 7:50pm UTC](https://discuss.elastic.co/t/how-to-complete-disable-tf-idf/70570/5 "2017-02-06T19:50:15Z")

</div>

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