# Cutoff\_frequency

**URL:** <https://discuss.elastic.co/t/cutoff-frequency/27387>\
**Category:** Вопросы на русском языке\
**Created:** [August 14, 2015, 10:38am UTC](https://discuss.elastic.co/t/cutoff-frequency/27387 "2015-08-14T10:38:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![111](https://avatars.discourse-cdn.com/v4/letter/1/0ea827/32.png) [@111](https://discuss.elastic.co/u/111)\
**Post date:** [August 14, 2015, 10:38am UTC](https://discuss.elastic.co/t/cutoff-frequency/27387/1 "2015-08-14T10:38:07Z")

</div>

Доброго времени суток!

У меня в индексе есть две записи:

```
"hits": [
     {
        "_index": "test",
        "_type": "test",
        "_id": "1",
        "_score": 1,
        "_source": {
           "text": "Quick and the dead"
        }
     },
     {
        "_index": "test",
        "_type": "test",
        "_id": "2",
        "_score": 1,
        "_source": {
           "text": "and the"
        }
     }
  ]

```

Рассмотрим запрос:

```
POST test/test/_search
{
    "query": {
        "match": {
            "text" : {
                "query" : "Quick and the dead",
                "cutoff_frequency" : 0.6
            }
        }
    }
}

```

Он выдаёт два результата, хотя согласно статье [https://www.elastic.co/guide/en/elasticsearch/guide/current/common-terms.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/common-terms.html)  
должен быть аналогичным запросу

```
POST test/test/_search
{
    "query": {
      "bool": {
        "must": { 
          "bool": {
            "should": [
              { "term": { "text": "quick" }},
              { "term": { "text": "dead" }}
            ]
          }
        },
        "should": { 
          "bool": {
            "should": [
              { "term": { "text": "and" }},
              { "term": { "text": "the" }}
            ]
          }
        }
      }
    }
}

```

Что не так? Заранее спасибо.

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [August 17, 2015, 1:51pm UTC](https://discuss.elastic.co/t/cutoff-frequency/27387/2 "2015-08-17T13:51:11Z")

</div>

Попробуйте запустить запрос с `search_type=dfs_query_then_fetch`. Возможно, что у Вас каждая запись на своей шарде находится, а по умолчанию частота рассчитывается на каждой шарде отдельно. Когда записей много - это работает. А вот во время экспериментов с 2-мя записями, как у Вас, получается что у всех слов одна и та же частота.

---

<div class="post-metadata">

**Author:** ![111](https://avatars.discourse-cdn.com/v4/letter/1/0ea827/32.png) [@111](https://discuss.elastic.co/u/111)\
**Post date:** [August 19, 2015, 12:14pm UTC](https://discuss.elastic.co/t/cutoff-frequency/27387/3 "2015-08-19T12:14:40Z")

</div>

Сработало так же, но причина, скорее всего, верная, спасибо.

---

<div class="post-metadata">

**Author:** ![111](https://avatars.discourse-cdn.com/v4/letter/1/0ea827/32.png) [@111](https://discuss.elastic.co/u/111)\
**Post date:** [August 19, 2015, 1:24pm UTC](https://discuss.elastic.co/t/cutoff-frequency/27387/4 "2015-08-19T13:24:33Z")

</div>

Вот такие пояснения выдаются по второму результату:

```
...
"_explanation": {
   "value": 0.2562107,
   "description": "product of:",
   "details": [
	  {
		 "value": 0.5124214,
		 "description": "sum of:",
		 "details": [
			{
			   "value": 0.2562107,
			   "description": "weight(text:and in 0) [PerFieldSimilarity], result of:",
			   "details": [
				  {
					 "value": 0.2562107,
					 "description": "score(doc=0,freq=1.0), product of:",
					 "details": [
						{
						   "value": 0.40993714,
						   "description": "queryWeight, product of:",
						   "details": [
							  {
								 "value": 1,
								 "description": "idf(docFreq=2, maxDocs=3)"
							  },
							  {
								 "value": 0.40993714,
								 "description": "queryNorm"
							  }
						   ]
						},
						{
						   "value": 0.625,
						   "description": "fieldWeight in 0, product of:",
						   "details": [
							  {
								 "value": 1,
								 "description": "tf(freq=1.0), with freq of:",
								 "details": [
									{
									   "value": 1,
									   "description": "termFreq=1.0"
									}
								 ]
							  },
							  {
								 "value": 1,
								 "description": "idf(docFreq=2, maxDocs=3)"
							  },
							  {
								 "value": 0.625,
								 "description": "fieldNorm(doc=0)"
							  }
						   ]
						}
					 ]
				  }
			   ]
			},
...

```

Видимо, maxDocs не может быть меньше 3?

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [August 19, 2015, 3:25pm UTC](https://discuss.elastic.co/t/cutoff-frequency/27387/5 "2015-08-19T15:25:25Z")

</div>

Похоже, что проблема в том, как `cutoff_frequency` используется [тут](https://github.com/apache/lucene-solr/blob/trunk/lucene/queries/src/java/org/apache/lucene/queries/CommonTermsQuery.java#L187). При округлении `(int) Math.ceil(maxTermFrequency * (float) maxDoc)` равнятся 2 для всех токенов. Все работает нормально с `"cutoff_frequency": 0.4`, например.

---

<div class="post-metadata">

**Author:** ![strikerdimabel](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@strikerdimabel](https://discuss.elastic.co/u/strikerdimabel)\
**Post date:** [November 24, 2015, 10:59am UTC](https://discuss.elastic.co/t/cutoff-frequency/27387/6 "2015-11-24T10:59:44Z")

</div>

Спасибо!

---

<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 6, 2017, 1:50pm UTC](https://discuss.elastic.co/t/cutoff-frequency/27387/7 "2017-07-06T13:50:30Z")

</div>


