# Elasticsearch: Replicating Google's Double Quote Exact Match Query

**URL:** <https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027>\
**Category:** Elasticsearch\
**Created:** [August 14, 2017, 10:15pm UTC](https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027 "2017-08-14T22:15:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![net](https://avatars.discourse-cdn.com/v4/letter/n/9de0a6/32.png) [@net](https://discuss.elastic.co/u/net)\
**Post date:** [August 14, 2017, 10:15pm UTC](https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027/1 "2017-08-14T22:15:42Z")

</div>

In google when you put double quotes around a phrase it does an exact match.

I see in elasticsearch how I can do an exact match on a given field. But I don't see how I can do an exact match over all the fields.

How can I do an exact match over all the fields in my index?

I've search for this many times and all the examples show how to do it for a given field. Please note I want to do this for every single field in my index.

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 15, 2017, 11:17am UTC](https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027/2 "2017-08-15T11:17:06Z")

</div>

There's a special metadata field called `_all` which contains all values of all fields concatenated as one big string. You could query that field using a `match_phrase` query:

```
GET my_index/_search
{
  "query": {
    "match_phrase": {
      "_all": "my query"
    }
  }
}

```

However, `_all` may be disabled in your mappings, and it's going away in the upcoming 6 release of Elasticsearch, so a better alternative may be to execute a `query_string` query in which you do not provide an explicit field, and in which you put your query between quotes (note the escaping):

```
GET my_index/_search
{
  "query": {
    "query_string": {
      "query": "\"my query\""
    }
  }
}

```

Depending on whether `_all` is enabled or not, this query will query the `_all` field, or it will execute an "all" query against all fields.

---

<div class="post-metadata">

**Author:** ![net](https://avatars.discourse-cdn.com/v4/letter/n/9de0a6/32.png) [@net](https://discuss.elastic.co/u/net)\
**Post date:** [August 15, 2017, 1:00pm UTC](https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027/3 "2017-08-15T13:00:56Z")

</div>

Thanks Abdon!

What will be the behavior if I do:

```
GET my_index/_search
{
  "query": {
    "query_string": {
      "query": "test this \"my query\""
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 15, 2017, 1:06pm UTC](https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027/4 "2017-08-15T13:06:47Z")

</div>

That query will default to an OR between `test`, `this` and the phrase `"my query"`. So any document matching either of these three will be considered a match.

---

<div class="post-metadata">

**Author:** ![net](https://avatars.discourse-cdn.com/v4/letter/n/9de0a6/32.png) [@net](https://discuss.elastic.co/u/net)\
**Post date:** [August 15, 2017, 1:16pm UTC](https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027/5 "2017-08-15T13:16:50Z")

</div>

Great, thanks! Looks good. I should be able to easily swap this into my existing code. I just want to double check one thing for my understanding.

And are these the same behavior?

```
GET my_index/_search
{
  "query": {
     "bool": {
         "must": {
                 "query_string": { "query": "regular search" }
          },
          ....
  }
}

```

and

```
GET my_index/_search
{
  "query": {
       "bool" {
           "must": {
                    "match": { "_all": "regular search" }
           },
           ...
  }
}
```

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 15, 2017, 1:28pm UTC](https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027/6 "2017-08-15T13:28:38Z")

</div>

Yes, these should match the same documents.

---

<div class="post-metadata">

**Author:** ![net](https://avatars.discourse-cdn.com/v4/letter/n/9de0a6/32.png) [@net](https://discuss.elastic.co/u/net)\
**Post date:** [August 15, 2017, 1:37pm UTC](https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027/7 "2017-08-15T13:37:46Z")

</div>

Excellent, thanks!

---

<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:** [September 12, 2017, 1:37pm UTC](https://discuss.elastic.co/t/elasticsearch-replicating-googles-double-quote-exact-match-query/97027/8 "2017-09-12T13:37:58Z")

</div>

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