# Match\_phrase with exact substring without space

**URL:** <https://discuss.elastic.co/t/match-phrase-with-exact-substring-without-space/315064>\
**Category:** Elasticsearch\
**Created:** [September 23, 2022, 10:07pm UTC](https://discuss.elastic.co/t/match-phrase-with-exact-substring-without-space/315064 "2022-09-23T22:07:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ansamHox](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@ansamHox](https://discuss.elastic.co/u/ansamHox)\
**Post date:** [September 23, 2022, 10:07pm UTC](https://discuss.elastic.co/t/match-phrase-with-exact-substring-without-space/315064/1 "2022-09-23T22:07:11Z")

</div>

I have a dataset like

```auto
Text: a==b==c==
Text: a==b== c==
Text: a== b==c==

```

And my own analyzer to create tokens for each letter

```auto
"analysis": {
	"analyzer": {
		"my_analyzer": {
			"char_filter": [
				"my_char_filter"
			],
			"tokenizer": "my_tokenizer"
		}
	},
	"char_filter": {
		"my_char_filter": {
			"pattern": "==",
			"type": "pattern_replace",
			"replacement": "==<>"
		}
	},
	"tokenizer": {
		"my_tokenizer": {
			"pattern": [
				"<>",
				" "
			],
			"type": "pattern"
		}
	}
}

```

When I search for a==b==c== with `match_phrase` (which I use because users often just search for first couple of letters), I get all 3 documents, but I want to get the exact word ("a==b==c=="), without whitespace.

This is the query I use

```auto
{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "Text": "a==b==c=="
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

```

How to achieve when I search for "ab" I get result containing "abcd" and not "ab c", or "a bc"

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [September 24, 2022, 4:46am UTC](https://discuss.elastic.co/t/match-phrase-with-exact-substring-without-space/315064/2 "2022-09-24T04:46:03Z")

</div>

Omit " " pattern from your pattern talknizer if possible. That's why a==b== c==and a==b== c== are analyzed to the same tokens.

[Analyzer API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html) will help you to make sure texts are analyzed intendedly.

---

<div class="post-metadata">

**Author:** ![ansamHox](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@ansamHox](https://discuss.elastic.co/u/ansamHox)\
**Post date:** [September 24, 2022, 6:59pm UTC](https://discuss.elastic.co/t/match-phrase-with-exact-substring-without-space/315064/3 "2022-09-24T18:59:55Z")

</div>

It's generating same tokens with or without " " pattern, and I can't even do that because in that case token will have empty space in the beginning after whitespace, e.g.

```auto
a==b== c==

```

will produce tokens: `[a,b, c] ` instead of `[a,b,c]`

---

<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:** [October 22, 2022, 6:59pm UTC](https://discuss.elastic.co/t/match-phrase-with-exact-substring-without-space/315064/4 "2022-10-22T18:59:56Z")

</div>

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