# Question on \`index\_phrases\` behavior

**URL:** https://discuss.elastic.co/t/question-on-index-phrases-behavior/180439
**Category:** Elasticsearch
**Created:** [May 9, 2019, 7:50pm UTC](https://discuss.elastic.co/t/question-on-index-phrases-behavior/180439 "2019-05-09T19:50:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)
#### Post date: [May 9, 2019, 7:50pm UTC](https://discuss.elastic.co/t/question-on-index-phrases-behavior/180439/1 "2019-05-09T19:50:24Z")

</div>

I'm looking at using `[index_phrases](https://www.elastic.co/guide/en/elasticsearch/reference/master/index-phrases.html)` instead of explicitly creating a subfield with shingles, but I'm a little confused on the behavior. Searching through the docs, I found a [promising link](https://www.elastic.co/guide/en/elasticsearch/reference/master/_faster_phrase_queries_with_literal_index_phrases_literal.html) titled "\_faster\_phrase\_queries\_with\_literal\_index\_phrases\_literal" but it 404s. Here's what I am trying to do:

```auto
#explore index_phrases behavior
DELETE en_docs
PUT en_docs
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text",
        "index_phrases": true
      }
    }
  }
}

POST en_docs/_doc/a
{
    "title": "James Charles wore the dress"
}
POST en_docs/_doc/b
{
    "title": "Charles James made the dress"
}
# Both docs have same score.
GET en_docs/_search
{
  "query": {
    "query_string": {
      "type": "most_fields",
      "query": "Charles James"
    }
  }
}
# Both docs have same score
GET en_docs/_search
{
  "query": {
    "match": {
      "title": "Charles James"
    }
  }
}

# Only doc b matches
GET en_docs/_search
{
  "query": {
    "query_string": {
      "query": "\"Charles James\""
    }
  }
}
# Only doc b matches
GET en_docs/_search
{
  "query": {
    "match_phrase": {
      "title": "Charles James"
    }
  }
}

```

I want to query on Charles James w/o quotes and have both docs returned, but with doc 'a' ranked higher. I was hoping that first `query_string` query with `most_fields` would do that for me, as that's what would happen if I had created a subfield with 2-word shingles.

Is the use case for `index_phrases` just for when you want to run `match_phrase` and wish it to run faster at the expense of a larger index?

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [May 10, 2019, 11:58am UTC](https://discuss.elastic.co/t/question-on-index-phrases-behavior/180439/2 "2019-05-10T11:58:42Z")

</div>

Hey Loren!

maybe I'm misreading things, but wouldnt a bool query with a `should` clause that contains a `match_phrase` and a `must` that contains the `match` query be what you are after?

The `match_phrase` query would internally go for the index phrases field, even if you specify `title` as the fieldname. See [https://github.com/elastic/elasticsearch/blob/7.0/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java#L649-L652](https://github.com/elastic/elasticsearch/blob/7.0/server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java#L649-L652)

--Alex

---

<div class="post-metadata">

### Author: ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)
#### Post date: [May 10, 2019, 1:24pm UTC](https://discuss.elastic.co/t/question-on-index-phrases-behavior/180439/3 "2019-05-10T13:24:24Z")

</div>

Thank you Alex!

Yes, I can do something like that. I think I was sort of expecting my search term to get analyzed into bigrams and then take advantage of that hidden index phrases field as part of the `query_string` query. That's what I'd get with an explicit bigram subfield, but it's a different use case really: searching on an explicit phrase versus boosting results that share arbitrary bigrams with the query term.

Using the lovely search profiler in Kibana I was able to see that a query like

```auto
{
  "query": {
    "query_string": {
      "query": "\"Charles James\" dress"
    }
  }
}

```

does make use of `title._index_phrase` under the hood via a `TermQuery`, so that will suit my needs after all.

Thanks again for your help.

---

<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: [June 7, 2019, 1:26pm UTC](https://discuss.elastic.co/t/question-on-index-phrases-behavior/180439/4 "2019-06-07T13:26:19Z")

</div>

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