# Weird Results with Pattern Analyzer

**URL:** https://discuss.elastic.co/t/weird-results-with-pattern-analyzer/178718
**Category:** Elasticsearch
**Created:** [April 26, 2019, 7:49pm UTC](https://discuss.elastic.co/t/weird-results-with-pattern-analyzer/178718 "2019-04-26T19:49:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vveluchamy](https://avatars.discourse-cdn.com/v4/letter/v/8797f3/32.png) [@vveluchamy](https://discuss.elastic.co/u/vveluchamy)
#### Post date: [April 26, 2019, 7:49pm UTC](https://discuss.elastic.co/t/weird-results-with-pattern-analyzer/178718/1 "2019-04-26T19:49:14Z")

</div>

Hello,

We have the following Tokenizers

"tokenizer": {  
"starts\_with\_tokenizer": {  
"type": "edge\_ngram",  
"min\_gram": "1",  
"max\_gram": "10"  
},  
"ngrams\_tokenizer": {  
"token\_chars": [  
"letter",  
"digit"  
],  
"min\_gram": "1",  
"type": "edge\_ngram",  
"max\_gram": "10"  
}  
}

We have the following analyzers

"analyzer": {  
"ngrams\_analyzer": {  
"filter": [  
"lowercase"  
],  
"type": "custom",  
"tokenizer": "ngrams\_tokenizer"  
},  
"starts\_with\_analyzer": {  
"filter": [  
"lowercase"  
],  
"type": "custom",  
"tokenizer": "starts\_with\_tokenizer"  
},  
"keyword\_lowercase\_analyzer": {  
"filter": [  
"lowercase"  
],  
"type": "custom",  
"tokenizer": "keyword"  
},  
"alphanumeric\_analyzer": {  
"lowercase": "true",  
"pattern": "[^a-zA-Z0-9áéíñóúüÁÉÍÑÓÚÜàâäôéèëêïîçùûüÿæœÀÂÄÔÉÈËÊÏÎŸÇÙÛÜÆŒäöüßÄÖÜẞàèéìíîòóùúÀÈÉÌÍÎÒÓÙÚ]",  
"type": "pattern"  
}  
}

And we have the following mappings

"fileName": {  
"type": "text",  
"fields": {  
"alphanumeric": {  
"analyzer": "alphanumeric\_analyzer",  
"type": "text"  
},  
"lowercase": {  
"analyzer": "keyword\_lowercase\_analyzer",  
"type": "text"  
},  
"ngrams": {  
"analyzer": "ngrams\_analyzer",  
"type": "text"  
},  
"keyword": {  
"type": "keyword"  
},  
"starts\_with": {  
"analyzer": "starts\_with\_analyzer",  
"type": "text"  
}  
}  
}

We indexed the below file name

RBK-CAT-CAT=CN6468\_P20z1\_ab44\_01.jpg

**Scenario 1**  
For the scenario, the below query returns results  
{  
"timeout": "1m",  
"from": 0,  
"size": 12,  
"sort": [  
{  
"sortKey": {  
"order": "asc"  
}  
}  
],  
"query": {  
"bool": {  
"filter": [  
{  
"bool": {  
"must": [  
{  
"terms": {  
"jobFolderID": [  
1316539,  
1317448  
]  
}  
},  
{  
"bool": {  
"should": [  
{  
"bool": {  
"must": [  
{  
"match": {  
"fileName.ngrams": {  
"query": "rbk",  
"operator": "and"  
}  
}  
},  
{  
"match": {  
"fileName.ngrams": {  
"query": "cat",  
"operator": "and"  
}  
}  
},  
{  
"match": {  
"fileName.ngrams": {  
"query": "cat",  
"operator": "and"  
}  
}  
},  
{  
"match": {  
"fileName.alphanumeric": {  
"type": "phrase\_prefix",  
"query": "cn6468\_p20z1\_ab44"  
}  
}  
}  
]  
}  
}  
]  
}  
}  
]  
}  
}  
]  
}  
}  
}

However, the below query does not return any result

{  
"timeout": "1m",  
"from": 0,  
"size": 12,  
"sort": [  
{  
"sortKey": {  
"order": "asc"  
}  
}  
],  
"query": {  
"bool": {  
"filter": [  
{  
"bool": {  
"must": [  
{  
"terms": {  
"jobFolderID": [  
1316539,  
1317448  
]  
}  
},  
{  
"bool": {  
"should": [  
{  
"bool": {  
"must": [  
{  
"match": {  
"fileName.ngrams": {  
"query": "rbk",  
"operator": "and"  
}  
}  
},  
{  
"match": {  
"fileName.ngrams": {  
"query": "cat",  
"operator": "and"  
}  
}  
},  
{  
"match": {  
"fileName.ngrams": {  
"query": "cat",  
"operator": "and"  
}  
}  
},  
{  
"match": {  
"fileName.alphanumeric": {  
"type": "phrase\_prefix",  
"query": "cn6468\_p20z1\_ab4"  
}  
}  
}  
]  
}  
}  
]  
}  
}  
]  
}  
}  
]  
}  
}  
}

**Scenario 2**  
Some of the sample phrase\_prefix queries that do not return results are 🙂

"match": {  
"fileName.alphanumeric": {  
"type": "phrase\_prefix",  
"query": "cn6468\_p20z1\_ab"  
}  
}

"match": {  
"fileName.alphanumeric": {  
"type": "phrase\_prefix",  
"query": "cn6468\_p20z1\_a"  
}  
}

**Question**

1. How this actually works?
2. Why I do not get some of the search-as-you-type type of queries?

Please help me to understand how this fileName.alphanumeric query works.

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: [May 24, 2019, 7:49pm UTC](https://discuss.elastic.co/t/weird-results-with-pattern-analyzer/178718/2 "2019-05-24T19:49:14Z")

</div>

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