# Is there any way to limit Term Frequency but keep function of proximity matching?

**URL:** <https://discuss.elastic.co/t/is-there-any-way-to-limit-term-frequency-but-keep-function-of-proximity-matching/772>\
**Category:** Elasticsearch\
**Created:** [May 15, 2015, 7:25pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-limit-term-frequency-but-keep-function-of-proximity-matching/772 "2015-05-15T19:25:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![go2jun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/go2jun/32/44837_2.png) [@go2jun](https://discuss.elastic.co/u/go2jun)\
**Post date:** [May 15, 2015, 7:25pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-limit-term-frequency-but-keep-function-of-proximity-matching/772/1 "2015-05-15T19:25:04Z")

</div>

Is there any way to limit Term Frequency but keep function of proximity matching ?

for example:

#1 Sue ate the alligator Sue leave. Then Sue work.  
#2 Sue look the alligator.  
#3 Sue alligator  
#4 Sue never goes anywhere without her alligator-skin purse

if search sue alligator

We expect the order: #3 #2 #1 #4

also #1 and #2 have the same score

If this is possible, then what's the best way to do this?

Thanks in advance

Jun

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [May 15, 2015, 8:09pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-limit-term-frequency-but-keep-function-of-proximity-matching/772/2 "2015-05-15T20:09:31Z")

</div>

This is a bit abstract for me - by proximity matching do you mean phrase  
matching? I don't believe there is a general, out of order ok, proximity  
query.

By limit term frequency, what is your goal? Is it about weighting? Maybe  
implementing a similarity via a plugin is the way to go about it.

---

<div class="post-metadata">

**Author:** ![go2jun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/go2jun/32/44837_2.png) [@go2jun](https://discuss.elastic.co/u/go2jun)\
**Post date:** [May 15, 2015, 8:33pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-limit-term-frequency-but-keep-function-of-proximity-matching/772/3 "2015-05-15T20:33:02Z")

</div>

Thanks Nik for reply!  
let me make it clearly this way:

1. for the search term “sue alligator” we prefer results where “sue” and “alligator” are close together. so #3 is thus better than #4. but we attribute no extra value to the word “sue” appearing multiple times. hence #1 is not better than #2.

so…we would like proximity of search words to result in higher scores, but we do not want term frequency to affect score at all. Is this possible or there is some way work around it?

also, could I use phrase matching within a has\_child query?

1. what If I want to disable term frequency for default simplify (TF/IDF), what's the easies way to do it other than a plugin?  
( I found it here, said:  
Setting index\_options to docs will disable term frequencies and term positions. A field with this mapping will not count how many times a term appears, and will not be usable for phrase or proximity queries  
[https://www.elastic.co/guide/en/elasticsearch/guide/master/scoring-theory.html](https://www.elastic.co/guide/en/elasticsearch/guide/master/scoring-theory.html)  
this make it lose proximity queries which is not we want)

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [May 15, 2015, 8:54pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-limit-term-frequency-but-keep-function-of-proximity-matching/772/4 "2015-05-15T20:54:21Z")

</div>

Looks like that's a good way then. You can use a phrase query for "sue  
alligator" and it'll work for in order phrases. You can set the phrase slop  
to pretty high and you'll get some proximity scoring. It doesn't handle out  
of order results iirc but its something.

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [May 15, 2015, 9:24pm UTC](https://discuss.elastic.co/t/is-there-any-way-to-limit-term-frequency-but-keep-function-of-proximity-matching/772/5 "2015-05-15T21:24:20Z")

</div>

I ran into this problem when implementing title search. You might find this  
blog post useful

> **[Title Search: when relevancy is only skin deep](https://opensourceconnections.com/blog/2014/12/08/title-search-when-relevancy-is-only-skin-deep/)**
>
> How do users judge that articles, books, and blog posts are relevant to what they’re searching for? What about you? If you’re searching for an article on ‘So...

---

<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, 12:13am UTC](https://discuss.elastic.co/t/is-there-any-way-to-limit-term-frequency-but-keep-function-of-proximity-matching/772/6 "2017-07-06T00:13:47Z")

</div>


