# Exact match in a not\_analyzed field

**URL:** https://discuss.elastic.co/t/exact-match-in-a-not-analyzed-field/37121
**Category:** Elasticsearch
**Created:** [December 14, 2015, 12:23pm UTC](https://discuss.elastic.co/t/exact-match-in-a-not-analyzed-field/37121 "2015-12-14T12:23:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Imran\_Azad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/imran_azad/32/4394_2.png) [@Imran\_Azad](https://discuss.elastic.co/u/Imran_Azad)
#### Post date: [December 14, 2015, 12:23pm UTC](https://discuss.elastic.co/t/exact-match-in-a-not-analyzed-field/37121/1 "2015-12-14T12:23:22Z")

</div>

How would I do an exact match on a not\_analyzed field that contains a large amount of text? For example take the following paragraph:

Kefir grains are a combination of lactic acid bacteria and yeasts in a matrix of proteins, lipids, and sugars, and this symbiotic matrix, (or SCOBY) forms "grains" that resemble cauliflower. For this reason, a complex and highly variable community of lactic acid bacteria and yeasts can be found in these grains although some predominate; Lactobacillus species are always present.[3] Even successive batches of kefir may differ due to factors such as the kefir grains rising out of the milk while fermenting, or curds forming around the grains, as well as room temperature.[8]

How can I get a match on a exact phrase search for "lactic acid bacteria and yeasts can be found in these grains" using the query\_string only?

---

<div class="post-metadata">

### Author: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [December 14, 2015, 5:41pm UTC](https://discuss.elastic.co/t/exact-match-in-a-not-analyzed-field/37121/2 "2015-12-14T17:41:17Z")

</div>

So, it is technically possible...but I want to discourage you from doing this. It will lead to poor performance in the long run. It's better to restructure your data now and leverage properly tokenized fields.

To make your query work, you need to query for the exact phrase (wrapped in quotes) with wildcards on either side:

```auto
GET /test/_search
{
    "query": {
        "query_string": {
           "default_field": "foo",
           "query": "*\"lactic acid bacteria and yeasts can be found in these grains\"*"
        }
    }
}

```

The reason this is terrible for performance is because a `not_analyzed` string is stored as a single token inside the index. To find the phrase, Lucene needs to look through every field then do a linear scan across the characters in that field to see if there is a match. This is _very_ slow because it does not leverage the index at all.

In contrast, if this field was an `analyzed` field, it would be tokenized, and the individual tokens would be stored in the index. A phrase search can then find all documents with the required tokens via the index, then execute a second phase to see if those documents have the terms in the correct ordering. This is much faster.

Sooo...I'd ask why this field is a `not_analyzed` field, and if you have the ability to analyze it instead? It would be much better to do this operation with a `match_phrase` for example.

---

<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, 11:31pm UTC](https://discuss.elastic.co/t/exact-match-in-a-not-analyzed-field/37121/3 "2017-07-05T23:31:13Z")

</div>


