# Unexpected results in regexp query

**URL:** <https://discuss.elastic.co/t/unexpected-results-in-regexp-query/19247>\
**Category:** Elasticsearch\
**Created:** [August 13, 2014, 9:06am UTC](https://discuss.elastic.co/t/unexpected-results-in-regexp-query/19247 "2014-08-13T09:06:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Markos\_Fragkakis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markos_fragkakis/32/1275_2.png) [@Markos\_Fragkakis](https://discuss.elastic.co/u/Markos_Fragkakis)\
**Post date:** [August 13, 2014, 9:06am UTC](https://discuss.elastic.co/t/unexpected-results-in-regexp-query/19247/1 "2014-08-13T09:06:05Z")

</div>

Hi all,

I have created my own mapping that does sentence tokenization:

This is the relevant part:

```
        "analysis": {
           "filter": {
              "csr_token_length_filter": {
                 "type": "length",
                 "max": "32776",
                 "min": "0"
              }
           },
           "char_filter": {
              "csr_new_line_character_filter": {
                 "type": "mapping",
                 "mappings": [
                    " -\\n => ",
                    " —\\n => ",
                    " \\n =>\\u0020"
                 ]
              }
           },
           "analyzer": {
              "csr_sentence_analyzer": {
                 "filter": "csr_token_length_filter",
                 "char_filter": [
                    "html_strip",
                    "csr_new_line_character_filter"
                 ],
                 "type": "custom",
                 "tokenizer": "csr_sentence_tokenizer"
              }
           },
           "tokenizer": {
              "csr_sentence_tokenizer": {
                 "flags": [
                    "NONE"
                 ],
                 "type": "pattern",
                 "pattern": "(?<=[.?!])\\s+(?=[\\da-zA-Z])"
              }
           }
        },

```

I am indexing a string containing the lorem ipsum text. So, when I tokenize  
it in marvel with this:

GET /markosindex/\_analyze?analyzer=csr\_sentence\_analyzer  
{  
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod  
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,  
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo  
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse  
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat  
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  
}

I get this:

{  
"tokens": [  
{  
"token": "{ Lorem ipsum dolor sit amet, consectetur adipisicing  
elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",  
"start\_offset": 0,  
"end\_offset": 126,  
"type": "word",  
"position": 1  
},  
{  
"token": "Ut enim ad minim veniam, quis nostrud exercitation  
ullamco laboris nisi ut aliquip ex ea commodo consequat.",  
"start\_offset": 127,  
"end\_offset": 234,  
"type": "word",  
"position": 2  
},  
{  
"token": "Duis aute irure dolor in reprehenderit in voluptate  
velit esse cillum dolore eu fugiat nulla pariatur.",  
"start\_offset": 235,  
"end\_offset": 337,  
"type": "word",  
"position": 3  
},  
{  
"token": "Excepteur sint occaecat cupidatat non proident, sunt in  
culpa qui officia deserunt mollit anim id est laborum. } ",  
"start\_offset": 338,  
"end\_offset": 451,  
"type": "word",  
"position": 4  
}  
]  
}

But when I run a regexp query on this field, I don't get any results:

GET /markosindex/\_search  
{

"fields" : ["filename", "mime"],

"query": {  
"filtered": {  
"query": {  
"regexp": {  
"fileTextContent.fileTextContentSentenceAnalyzed":  
"._consectetur\s+adipisicing\s+elit._"  
}  
},  
"filter" : {  
"query" : {  
"match\_all" : { }  
}  
}  
}  
},  
"highlight": {  
"fields": {"fileTextContent.fileTextContentSentenceAnalyzed": {}}}  
}

However, when I change the intermediate "\s+" to ".+", the query works:

GET /markosindex/\_search  
{

"fields" : ["filename", "mime"],

"query": {  
"filtered": {  
"query": {  
"regexp": {  
"fileTextContent.fileTextContentSentenceAnalyzed":  
"._consectetur.+adipisicing.+elit._"  
}  
},  
"filter" : {  
"query" : {  
"match\_all" : { }  
}  
}  
}  
},  
"highlight": {  
"fields": {"fileTextContent.fileTextContentSentenceAnalyzed": {}}}  
}

Any idea what is going on? My analyzer shows spaces between words in each  
token (sentence). However, the regexp query does not work for me.

Cheers,

Markos

--  
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/a89f8dfc-16b0-46c7-b0ae-f68f1ac9079f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a89f8dfc-16b0-46c7-b0ae-f68f1ac9079f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Markos\_Fragkakis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markos_fragkakis/32/1275_2.png) [@Markos\_Fragkakis](https://discuss.elastic.co/u/Markos_Fragkakis)\
**Post date:** [August 13, 2014, 9:13am UTC](https://discuss.elastic.co/t/unexpected-results-in-regexp-query/19247/2 "2014-08-13T09:13:44Z")

</div>

Forgot to add the relevant part of my mapping:

```
           "fileTextContent": {
              "type": "string",
              "index": "no",
              "fields": {
                 "fileTextContentSentenceAnalyzed": {
                    "type": "string",
                    "analyzer": "csr_sentence_analyzer"
                 },
                 "fileTextContentAnalyzed": {
                    "type": "string"
                 }
              }
           },

```

--  
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/30900d12-e36d-4059-9b88-dbd81c240708%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/30900d12-e36d-4059-9b88-dbd81c240708%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:09am UTC](https://discuss.elastic.co/t/unexpected-results-in-regexp-query/19247/3 "2017-07-06T01:09:00Z")

</div>


