# Elastic term frequency query

**URL:** <https://discuss.elastic.co/t/elastic-term-frequency-query/7704>\
**Category:** Elasticsearch\
**Created:** [May 15, 2012, 3:14pm UTC](https://discuss.elastic.co/t/elastic-term-frequency-query/7704 "2012-05-15T15:14:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan\_Zinchenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan_zinchenko/32/2703_2.png) [@Ivan\_Zinchenko](https://discuss.elastic.co/u/Ivan_Zinchenko)\
**Post date:** [May 15, 2012, 3:14pm UTC](https://discuss.elastic.co/t/elastic-term-frequency-query/7704/1 "2012-05-15T15:14:40Z")

</div>

Hi everyone,

anybody had to deal with the type of term frequency queries like: "match  
documents that have W word in F field at least N times"?  
seems like dismax is not the right medicine here, and there are no  
dedicated term freq query as far as i know.

i actually managed to do that using span query, for example - match 'word'  
in 'field' at least 3 times:  
{  
"span\_near": {  
"clauses": [  
{  
"span\_term": {  
"field": "word"  
}  
},  
{  
"span\_term": {  
"field": "word"  
}  
},  
{  
"span\_term": {  
"field": "word"  
}  
}  
],  
"slop": 2147483647,  
"in\_order": true  
}  
}

is this the only way of doing that, optimal way? or am i missing something?

Thx.

---

<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, 3:28am UTC](https://discuss.elastic.co/t/elastic-term-frequency-query/7704/2 "2017-07-06T03:28:49Z")

</div>

Closed on July 6, 2017, 3:28am UTC


