# ElasticSearch with n word separation and regular expression (with Tire gem)

**URL:** <https://discuss.elastic.co/t/elasticsearch-with-n-word-separation-and-regular-expression-with-tire-gem/12845>\
**Category:** Elasticsearch\
**Created:** [July 18, 2013, 4:06pm UTC](https://discuss.elastic.co/t/elasticsearch-with-n-word-separation-and-regular-expression-with-tire-gem/12845 "2013-07-18T16:06:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![William](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/william/32/2218_2.png) [@William](https://discuss.elastic.co/u/William)\
**Post date:** [July 18, 2013, 4:06pm UTC](https://discuss.elastic.co/t/elasticsearch-with-n-word-separation-and-regular-expression-with-tire-gem/12845/1 "2013-07-18T16:06:48Z")

</div>

I am using ElasticSearch (with the Tire gem). I have the following query  
which will match escaped cat, escaped black cat, etc.

I was wondering, is it possible to ask ElasticSearch to search with the  
following criteria:

1. "escaped [exactly 0 or 1 word] cat" ie) escaped \w{0,1} cat
2. "escaped [n words] cat" ie) escaped \w{n} cat
3. "escaped [Regular expression here] cat" ie) escaped (big|black|white)  
cat

Thanks

Current searching query:

{  
"query": {  
"bool": {  
"should": [  
{  
"query\_string": {  
"query": ""escaped ? cat"",  
"analyzer": "snowball"  
}  
},  
{  
"query\_string": {  
"query": ""escaped ? cat"",  
"default\_operator": "and"  
}  
},  
{  
"flt\_field": {  
"content": {  
"like\_text": ""escaped ? cat""  
}  
}  
},  
{  
"mlt\_field": {  
"content": {  
"like\_text": ""escaped ? cat""  
}  
}  
}  
]  
}  
}}

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [July 19, 2013, 6:17am UTC](https://discuss.elastic.co/t/elasticsearch-with-n-word-separation-and-regular-expression-with-tire-gem/12845/2 "2013-07-19T06:17:48Z")

</div>

Hey,

the slop parameter might help you in your first two cases. (Search for slop  
on the .org documentation, it is mentioned in the match and in the  
query\_string query at least). Your regular expression case might be  
solvable with the regexp filter, but it might be to slow. You might be able  
to work around by using a bool query and the minimum\_should\_match parameter

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

I am afraid I cannot help you with Tire though...

--Alex

On Thu, Jul 18, 2013 at 6:06 PM, William [bill@theworkinggroup.ca](mailto:bill@theworkinggroup.ca) wrote:

> I am using Elasticsearch (with the Tire gem). I have the following query  
> which will match escaped cat, escaped black cat, etc.
> 
> I was wondering, is it possible to ask Elasticsearch to search with the  
> following criteria:
> 
> 1. "escaped [exactly 0 or 1 word] cat" ie) escaped \w{0,1} cat
> 2. "escaped [n words] cat" ie) escaped \w{n} cat
> 3. "escaped [Regular expression here] cat" ie) escaped  
> (big|black|white) cat
> 
> Thanks
> 
> Current searching query:
> 
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "query\_string": {  
> "query": ""escaped ? cat"",  
> "analyzer": "snowball"  
> }  
> },  
> {  
> "query\_string": {  
> "query": ""escaped ? cat"",  
> "default\_operator": "and"  
> }  
> },  
> {  
> "flt\_field": {  
> "content": {  
> "like\_text": ""escaped ? cat""  
> }  
> }  
> },  
> {  
> "mlt\_field": {  
> "content": {  
> "like\_text": ""escaped ? cat""  
> }  
> }  
> }  
> ]  
> }  
> }}
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:25am UTC](https://discuss.elastic.co/t/elasticsearch-with-n-word-separation-and-regular-expression-with-tire-gem/12845/3 "2017-07-06T02:25:33Z")

</div>

Closed on July 6, 2017, 2:25am UTC


