# How to disable TF/IDF completely

**URL:** <https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518>\
**Category:** Elasticsearch\
**Created:** [March 12, 2018, 9:51am UTC](https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518 "2018-03-12T09:51:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmadazimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadazimi/32/25247_2.png) [@ahmadazimi](https://discuss.elastic.co/u/ahmadazimi)\
**Post date:** [March 12, 2018, 9:51am UTC](https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518/1 "2018-03-12T09:51:31Z")

</div>

I'm trying to query small pieces of sentences in about 500k records and TF/IDF makes results so bad. I wanna disable it at index time or query time (without using constant\_score).

Has anyone has any idea?!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 12, 2018, 10:26am UTC](https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518/2 "2018-03-12T10:26:33Z")

</div>

> [@ahmadazimi](#):
>
> and TF/IDF makes results so bad.

What do you mean?

---

<div class="post-metadata">

**Author:** ![ahmadazimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadazimi/32/25247_2.png) [@ahmadazimi](https://discuss.elastic.co/u/ahmadazimi)\
**Post date:** [March 12, 2018, 11:37am UTC](https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518/3 "2018-03-12T11:37:27Z")

</div>

I only need check if a term exists or not in the field, but TF/IDF use word order, count and frequency which they make final scores not acceptable in my case.

PS1. boosts are too important for each fields separately.

PS2. I should use multi\_match query (cross\_fields)

PS3. this is my mapping params for one field:  
'search' =\> [  
'type' =\> 'text',  
'norms' =\> false,  
'index\_options' =\> 'docs',  
'analyzer' =\> 'index\_time\_persian',  
'search\_analyzer' =\> 'search\_time\_persian',  
'term\_vector' =\> 'with\_positions\_offsets',  
],

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 12, 2018, 12:15pm UTC](https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518/4 "2018-03-12T12:15:15Z")

</div>

So you want to use a `term` query within a `bool -> filter` clause, no?

May be I misunderstand in which case provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem.

---

<div class="post-metadata">

**Author:** ![byronvoorbach](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/byronvoorbach/32/8283_2.png) [@byronvoorbach](https://discuss.elastic.co/u/byronvoorbach)\
**Post date:** [March 12, 2018, 3:44pm UTC](https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518/5 "2018-03-12T15:44:22Z")

</div>

You could use [constant\_score](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html) query in order to disregard TF/IDF 🙂

---

<div class="post-metadata">

**Author:** ![ahmadazimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadazimi/32/25247_2.png) [@ahmadazimi](https://discuss.elastic.co/u/ahmadazimi)\
**Post date:** [March 13, 2018, 7:58am UTC](https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518/6 "2018-03-13T07:58:14Z")

</div>

Thank you @dadoonet  
Ok, I'll prepare it as soon as possible.

---

<div class="post-metadata">

**Author:** ![ahmadazimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmadazimi/32/25247_2.png) [@ahmadazimi](https://discuss.elastic.co/u/ahmadazimi)\
**Post date:** [March 13, 2018, 7:59am UTC](https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518/7 "2018-03-13T07:59:19Z")

</div>

@byronvoorbach Unfortunately constant\_score completely remove my fields boosting and return 0 or 1 as score. I can't use it in a normal way.

---

<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:** [April 10, 2018, 7:59am UTC](https://discuss.elastic.co/t/how-to-disable-tf-idf-completely/123518/8 "2018-04-10T07:59:33Z")

</div>

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