# Regexp Filter boost

**URL:** <https://discuss.elastic.co/t/regexp-filter-boost/21715>\
**Category:** Elasticsearch\
**Created:** [January 19, 2015, 5:13pm UTC](https://discuss.elastic.co/t/regexp-filter-boost/21715 "2015-01-19T17:13:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Irwin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_irwin/32/985_2.png) [@Michael\_Irwin](https://discuss.elastic.co/u/Michael_Irwin)\
**Post date:** [January 19, 2015, 5:13pm UTC](https://discuss.elastic.co/t/regexp-filter-boost/21715/1 "2015-01-19T17:13:41Z")

</div>

Hello,

I'm trying to figure out if it's possible to boost hits based on a regexp.  
For example, searching through records with user's names, I'd like to boost  
those that start with the query. I've tried a query like the following but  
it doesn't work like I'd like:

{  
"query": {  
"function\_score": {  
"functions": [  
{  
"boost\_factor": 2,  
"filter": {  
"regexp": {  
"name\_not\_analyzed": "^frank.\*"  
}  
}  
}  
],  
"score\_mode": "multiply",  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"query": "frank",  
"default\_operator": "AND"  
}  
},  
{  
"term": {  
"site\_id": {  
"term": 1  
}  
}  
}  
]  
}  
}  
}  
}  
}

Is this possible? If so, how? Thanks!

--  
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/8bb66f5f-7b98-4c22-b9d1-1254fa768ab4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8bb66f5f-7b98-4c22-b9d1-1254fa768ab4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Michael\_Irwin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_irwin/32/985_2.png) [@Michael\_Irwin](https://discuss.elastic.co/u/Michael_Irwin)\
**Post date:** [January 19, 2015, 7:47pm UTC](https://discuss.elastic.co/t/regexp-filter-boost/21715/2 "2015-01-19T19:47:15Z")

</div>

I think I've figured out another way to do what I want. This seems to work:

{  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"query": "frank",  
"default\_operator": "AND"  
}  
},  
{  
"term": {  
"site\_id": {  
"term": 1  
}  
}  
}  
],  
"should": [  
{  
"match\_phrase\_prefix": {  
"name": {  
"query": "frank",  
"max\_expansions": 5  
}  
}  
}  
]  
}  
}  
}

when using the analyzer as explained in

> **[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.

On Monday, January 19, 2015 at 12:13:42 PM UTC-5, Michael Irwin wrote:

> Hello,
> 
> I'm trying to figure out if it's possible to boost hits based on a regexp.  
> For example, searching through records with user's names, I'd like to boost  
> those that start with the query. I've tried a query like the following  
> but it doesn't work like I'd like:
> 
> {  
> "query": {  
> "function\_score": {  
> "functions": [  
> {  
> "boost\_factor": 2,  
> "filter": {  
> "regexp": {  
> "name\_not\_analyzed": "^frank.\*"  
> }  
> }  
> }  
> ],  
> "score\_mode": "multiply",  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "query\_string": {  
> "query": "frank",  
> "default\_operator": "AND"  
> }  
> },  
> {  
> "term": {  
> "site\_id": {  
> "term": 1  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }
> 
> Is this possible? If so, how? Thanks!

--  
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/154c83d7-17cc-490f-a64b-b5e6f7a95b8d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/154c83d7-17cc-490f-a64b-b5e6f7a95b8d%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, 12:37am UTC](https://discuss.elastic.co/t/regexp-filter-boost/21715/3 "2017-07-06T00:37:56Z")

</div>

Closed on July 6, 2017, 12:37am UTC


