# Match\_phrase vs simple\_query\_string

**URL:** <https://discuss.elastic.co/t/match-phrase-vs-simple-query-string/368560>\
**Category:** Elastic Search\
**Created:** [October 9, 2024, 7:52pm UTC](https://discuss.elastic.co/t/match-phrase-vs-simple-query-string/368560 "2024-10-09T19:52:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sdmccorm](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@sdmccorm](https://discuss.elastic.co/u/sdmccorm)\
**Post date:** [October 9, 2024, 7:52pm UTC](https://discuss.elastic.co/t/match-phrase-vs-simple-query-string/368560/1 "2024-10-09T19:52:03Z")

</div>

Folks - I'm not even sure what kind of search this is called. I'm searching some logs, but the problem is each log starts with the same text - but the string can end with other text. Is there a way to do this without regex?

Example:

They all start with this - but I want to ignore any text that IS ONLY THIS STRING.

Skip this:  
"Generic Error found."

However, if it contains that string AND additional text, I need to match the entire string:

Match this:  
"Generic Error found. - some specific error text"

I was hoping a match\_phrase did it but, it's still matching any string that includes the starting text.

Just point me in the right direction with the type of query I need to run, please.

```auto
{
"match_phrase": {
       "field": {
       "query": "Generic Error found. "
   }
 }
}

```

Thanks,  
Steve

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [October 9, 2024, 8:39pm UTC](https://discuss.elastic.co/t/match-phrase-vs-simple-query-string/368560/2 "2024-10-09T20:39:39Z")

</div>

You may want to do a boolean query, where you can filter out for exact matches of the String you want, but include the strings that you want.

---

<div class="post-metadata">

**Author:** ![Carlos\_Sponchiado](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_sponchiado/32/11077_2.png) [@Carlos\_Sponchiado](https://discuss.elastic.co/u/Carlos_Sponchiado)\
**Post date:** [October 9, 2024, 10:18pm UTC](https://discuss.elastic.co/t/match-phrase-vs-simple-query-string/368560/3 "2024-10-09T22:18:48Z")

</div>

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "field": "Generic Error found."
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "field.keyword": "Generic Error found."
          }
        }
      ]
    }
  }
}

```

---

<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:** [November 6, 2024, 10:19pm UTC](https://discuss.elastic.co/t/match-phrase-vs-simple-query-string/368560/4 "2024-11-06T22:19:24Z")

</div>

Closed on November 6, 2024, 10:19pm UTC

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