# How to give more preference to first word of the stored index

**URL:** <https://discuss.elastic.co/t/how-to-give-more-preference-to-first-word-of-the-stored-index/59783>\
**Category:** Elasticsearch\
**Created:** [September 5, 2016, 6:51am UTC](https://discuss.elastic.co/t/how-to-give-more-preference-to-first-word-of-the-stored-index/59783 "2016-09-05T06:51:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahul16](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rahul16](https://discuss.elastic.co/u/rahul16)\
**Post date:** [September 5, 2016, 6:51am UTC](https://discuss.elastic.co/t/how-to-give-more-preference-to-first-word-of-the-stored-index/59783/1 "2016-09-05T06:51:41Z")

</div>

I have an index of college with fields college\_name,short\_form,city\_name,state\_name.  
suppose i search for the string 'college of' and want to get :  
'college of enginners' above 'indian college of law' and 'punjab college of commerce'.

Plzz, help me i am struck

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [September 5, 2016, 8:48am UTC](https://discuss.elastic.co/t/how-to-give-more-preference-to-first-word-of-the-stored-index/59783/2 "2016-09-05T08:48:29Z")

</div>

You can try the `span_first` query:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html)

```auto
"span_first": {
  "match": {
    "span_term": {
      "text": "college"
     }
 },
 "end": 1,
 "boost": 10
}

```

You could for instance add this query in a should clause of your main boolean query and set the boost to something high in order to ensure that hits with a field where the first word is "college" are ranked higher.

---

<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 5, 2017, 10:22pm UTC](https://discuss.elastic.co/t/how-to-give-more-preference-to-first-word-of-the-stored-index/59783/3 "2017-07-05T22:22:31Z")

</div>


