# How to match trailing spaces in searches?

**URL:** <https://discuss.elastic.co/t/how-to-match-trailing-spaces-in-searches/186292>\
**Category:** Elasticsearch\
**Created:** [June 18, 2019, 3:07pm UTC](https://discuss.elastic.co/t/how-to-match-trailing-spaces-in-searches/186292 "2019-06-18T15:07:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bart\_de\_Man](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bart_de_man/32/48319_2.png) [@Bart\_de\_Man](https://discuss.elastic.co/u/Bart_de_Man)\
**Post date:** [June 18, 2019, 3:07pm UTC](https://discuss.elastic.co/t/how-to-match-trailing-spaces-in-searches/186292/1 "2019-06-18T15:07:55Z")

</div>

Hello all,

I'm currently trying to match trailing/leading spaces in searches such as:

- "de "
- "het "
- "een "
- " baan"

the field that im searching on is of type "text" with a search\_analyzer "simple"

```auto
'my_searching_field' => [
        'type' => 'text',
        'analyzer' => 'autocomplete_mycustom',
        'search_analyzer' => 'simple',
    ],

'autocomplete_mycustom' => [
                            'tokenizer' => 'standard',
                            'filter' => 'lowercase, ngram_mycustomn'
                        ]

'ngram_mycustomn' => [
                            'type' => 'ngram',
                            'min_gram' => '1',
                            'max_gram' => '20',
                            'token_chars' => ['letter', 'digit', 'whitespace', 'symbol', 'punctuation'],
                        ]

```

Example values of said field within my documents:

"de bloem"  
"denneboom"  
"het is goed"  
"hetterdo"  
"de baan voor"

Where I would like to be able to search for: "de " (notice the trailing space) and match "de bloem", but not match "denbeboom".

Another example:  
searching for " baan", where i would like to match "de baan voor".

Is this possible? And how would i achieve this?

Thanks in advance!

---

<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 16, 2019, 3:07pm UTC](https://discuss.elastic.co/t/how-to-match-trailing-spaces-in-searches/186292/2 "2019-07-16T15:07:57Z")

</div>

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