# How can I do a “match\_phrase” that ranks solely on “does the phrase exists”?

**URL:** https://discuss.elastic.co/t/how-can-i-do-a-match-phrase-that-ranks-solely-on-does-the-phrase-exists/238976
**Category:** Elasticsearch
**Created:** [June 27, 2020, 10:21pm UTC](https://discuss.elastic.co/t/how-can-i-do-a-match-phrase-that-ranks-solely-on-does-the-phrase-exists/238976 "2020-06-27T22:21:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![chrislentz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrislentz/32/71251_2.png) [@chrislentz](https://discuss.elastic.co/u/chrislentz)
#### Post date: [June 27, 2020, 10:21pm UTC](https://discuss.elastic.co/t/how-can-i-do-a-match-phrase-that-ranks-solely-on-does-the-phrase-exists/238976/1 "2020-06-27T22:21:22Z")

</div>

Is there a way to make “match\_phrase” only look for a match, but not take other things into account, like the match in relation to other terms in the text field?

i.e. If I search "star wars", "Star Wars: Revelations" receives a hire score than "Star Wars: The Last Jedi" because "Star Wars: Revelations" has 3 terms vs "Star Wars: The Last Jedi" which has 5 terms.

I would like all of them to receive a consistent score. Because I am then using function\_score to rank them on an internal popularity value.

I guess I am looking for something like does the text field have the term? Score is: yes=1 no=0

---

<div class="post-metadata">

### Author: ![Julien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julien/32/19688_2.png) [@Julien](https://discuss.elastic.co/u/Julien)
#### Post date: [June 29, 2020, 8:57pm UTC](https://discuss.elastic.co/t/how-can-i-do-a-match-phrase-that-ranks-solely-on-does-the-phrase-exists/238976/2 "2020-06-29T20:57:35Z")

</div>

That should be possible with [constant score](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html), something like this for default boost/score of `1.0` for every match and will not return documents which do not match here:

```auto
GET my_index/_search
{
  "query": {
    "constant_score": {
      "filter": {
        "match_phrase": {
          "title": "Star Wars"
        }
      }
    }
  }
}

```

Or if the aim is to return all documenst with a `title` field and add score 1 to the phrase matches (other docs will have score 0):

```auto
GET my_index/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "exists": {
            "field": "title"
          }
        }
      ],
      "should": [
        {
          "constant_score": {
            "filter": {
              "match_phrase": {
                "title": "Star Wars"
              }
            }
          }
        }
      ]
    }
  }
}

```

---

<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 27, 2020, 9:07pm UTC](https://discuss.elastic.co/t/how-can-i-do-a-match-phrase-that-ranks-solely-on-does-the-phrase-exists/238976/3 "2020-07-27T21:07:46Z")

</div>

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