# Pattern\_capture filter emits a token that is not matched with pattern also

**URL:** <https://discuss.elastic.co/t/pattern-capture-filter-emits-a-token-that-is-not-matched-with-pattern-also/19284>\
**Category:** Elasticsearch\
**Created:** [August 14, 2014, 12:13pm UTC](https://discuss.elastic.co/t/pattern-capture-filter-emits-a-token-that-is-not-matched-with-pattern-also/19284 "2014-08-14T12:13:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raj\_2](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@Raj\_2](https://discuss.elastic.co/u/Raj_2)\
**Post date:** [August 14, 2014, 12:13pm UTC](https://discuss.elastic.co/t/pattern-capture-filter-emits-a-token-that-is-not-matched-with-pattern-also/19284/1 "2014-08-14T12:13:22Z")

</div>

```
 I have a case where I have to extract domain part from emails that are 

```

found in a text. I used uax\_url\_email tokenizer to create emails as a  
single. And I have a pattern\_capture filter which will emit "@(.+)" pattern  
string. But uax\_url\_email also return words also which is not an email and  
the pattern capture filter does not filter that. Any suggestions?

"custom\_analyzer":{  
"tokenizer": "uax\_url\_email",  
"filter": [  
"email\_domain\_filter"  
]  
}  
"filter": {  
"email\_domain\_filter":{  
"type": "pattern\_capture",  
"preserve\_original": false,  
"patterns": [  
"@(.+)"  
]  
}  
}

_input string_ : "my email id is [xyz@gmail.com](mailto:xyz@gmail.com)"  
_Output tokens:_ my, email, id, is, [gmail.com](http://gmail.com)

But I need only [gmail.com](http://gmail.com)

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3de51758-bb99-46c6-b47c-a68004de8eb8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3de51758-bb99-46c6-b47c-a68004de8eb8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![haight6716](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/haight6716/32/7545_2.png) [@haight6716](https://discuss.elastic.co/u/haight6716)\
**Post date:** [February 2, 2016, 10:00pm UTC](https://discuss.elastic.co/t/pattern-capture-filter-emits-a-token-that-is-not-matched-with-pattern-also/19284/2 "2016-02-02T22:00:34Z")

</div>

I have a similar problem using pattern capture. In my case, it "feels" like preserve\_original: false isn't working. I'm getting tokens that don't match my patterns. My document includes the text ":::" which is being picked up as a token, but my filter allows only [a-z0-9].

```
        "analysis": {
            "filter": {
                "ipnwords": {
                    "type": "pattern_capture",
                    "preserve_original": false,
                    "patterns": [
                        "^([a-z0-9]+)$"
                    ]
                }
            },
            "analyzer": {
                "words": {
                    "tokenizer": "ipwords",
                    "filter": ["lowercase", "ipnwords", "unique"]
                }
            },
            "tokenizer": {
                "ipwords": {
                    "type": "pattern",
                    "pattern": "[a-zA-Z0-9:\\.-]+",
                    "group": 0
                }
            }
        }

```

You can see my tokenizer is picking up colons, but my filter should be dropping tokens with colon. Ultimately, I'll include patterns that allow colon in specific situations, so I can't just drop it from the tokenizer.

---

<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:19pm UTC](https://discuss.elastic.co/t/pattern-capture-filter-emits-a-token-that-is-not-matched-with-pattern-also/19284/3 "2017-07-05T23:19:27Z")

</div>


