# Boost, scoring and phrase search

**URL:** <https://discuss.elastic.co/t/boost-scoring-and-phrase-search/4664>\
**Category:** Elasticsearch\
**Created:** [June 20, 2011, 9:15pm UTC](https://discuss.elastic.co/t/boost-scoring-and-phrase-search/4664 "2011-06-20T21:15:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yannick\_Smits\_2](https://avatars.discourse-cdn.com/v4/letter/y/a4c791/32.png) [@Yannick\_Smits\_2](https://discuss.elastic.co/u/Yannick_Smits_2)\
**Post date:** [June 20, 2011, 9:15pm UTC](https://discuss.elastic.co/t/boost-scoring-and-phrase-search/4664/1 "2011-06-20T21:15:25Z")

</div>

- 

```
     Can we have query time index boost levels?

```

- 

```
     How would you implement formatting based boosting. For instance

```

have bold, italic and uppercase texts (HTML) have higher scores?

- 

```
     I noticed phrase searches actually don't limit the search results

```

in to matches in 1 phrase. So when searching for "fear of dark" it will also  
match if fear and dark appear in different sentences ("Then it became dark.  
He had fear of cats."). Is there a way to force the result to be in the same  
sentence?

- 

```
     Is proximity of words also taken into account when doing a

```

multi-word phrase search (the closer words appear the higher the scoring?)

Thanks,  
Yannick

---

<div class="post-metadata">

**Author:** ![Yannick\_Smits\_2](https://avatars.discourse-cdn.com/v4/letter/y/a4c791/32.png) [@Yannick\_Smits\_2](https://discuss.elastic.co/u/Yannick_Smits_2)\
**Post date:** [June 22, 2011, 6:50am UTC](https://discuss.elastic.co/t/boost-scoring-and-phrase-search/4664/2 "2011-06-22T06:50:51Z")

</div>

Could somebody help me with my Monday questions? Even if you only know the  
answer to 1 of them it would be very helpful.

Thanks,  
Yannick

From: Yannick Smits [[mailto:mailinglists@goyaweb.nl](mailto:mailinglists@goyaweb.nl)]  
Sent: maandag 20 juni 2011 23:15  
To: [users@elasticsearch.com](mailto:users@elasticsearch.com)  
Subject: boost, scoring and phrase search

- 

```
     Can we have query time index boost levels?

```

- 

```
     How would you implement formatting based boosting. For instance

```

have bold, italic and uppercase texts (HTML) have higher scores?

- 

```
     I noticed phrase searches actually don't limit the search results

```

in to matches in 1 phrase. So when searching for "fear of dark" it will also  
match if fear and dark appear in different sentences ("Then it became dark.  
He had fear of cats."). Is there a way to force the result to be in the same  
sentence?

- 

```
     Is proximity of words also taken into account when doing a

```

multi-word phrase search (the closer words appear the higher the scoring?)

Thanks,  
Yannick

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [June 22, 2011, 11:40am UTC](https://discuss.elastic.co/t/boost-scoring-and-phrase-search/4664/3 "2011-06-22T11:40:42Z")

</div>

Hi Yannick

On Mon, 2011-06-20 at 23:15 +0200, Yannick Smits wrote:

> - 
> 
> ```
> Can we have query time index boost levels?
> 
> ```

Yes. Look at the Query DSL docs - most queries take a 'boost'  
parameter.

> - 
> 
> ```
> How would you implement formatting based boosting. For
> 
> ```
> 
> instance have bold, italic and uppercase texts (HTML) have higher  
> scores?

I don't think you can (at least not currently)

> - 
> 
> ```
> I noticed phrase searches actually donât limit the search
> 
> ```
> 
> results in to matches in 1 phrase. So when searching for âfear of  
> darkâ it will also match if fear and dark appear in different  
> sentences (âThen it became dark. He had fear of cats.â). Is there a  
> way to force the result to be in the same sentence?

I think you mean a 'text' query, not a 'text\_phrase' query. A text  
query will match text that contains the same words. A text\_phrase query  
will find text that includes exactly the same phrase (ignoring stop  
words like 'of').

You can set the slop factor for text\_phrase queries so that the words  
don't have to be right next to each other.

> - 
> 
> ```
> Is proximity of words also taken into account when doing a
> 
> ```
> 
> multi-word phrase search (the closer words appear the higher the  
> scoring?)

With the text\_phrase query, and slop, yes: proximity is taken into  
account.

clint

---

<div class="post-metadata">

**Author:** ![Yannick\_Smits\_2](https://avatars.discourse-cdn.com/v4/letter/y/a4c791/32.png) [@Yannick\_Smits\_2](https://discuss.elastic.co/u/Yannick_Smits_2)\
**Post date:** [June 22, 2011, 1:57pm UTC](https://discuss.elastic.co/t/boost-scoring-and-phrase-search/4664/4 "2011-06-22T13:57:44Z")

</div>

Hi Clinton,

1. I had a look at the docs but could not find a way to specify a boost value based on indices the documents are in, at query time, only as a configuration/static ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/index-boost.html)). What am I missing?

2. could you think of a strategy to simulate such a behavior? Like extracting the bold words and saving them with a higher boost to a different field or something without screwing up the highlighting feature?

3. yes, I'm using text\_phrase. But still I would like to know if it is possible to have it look only within the phrase for the specified terms instead of matching over multiple phrases.

Thanks,  
Yannick

-----Original Message-----  
From: Clinton Gormley [[mailto:clinton@iannounce.co.uk](mailto:clinton@iannounce.co.uk)]  
Sent: woensdag 22 juni 2011 13:41  
To: [users@elasticsearch.com](mailto:users@elasticsearch.com)  
Subject: Re: boost, scoring and phrase search

Hi Yannick

On Mon, 2011-06-20 at 23:15 +0200, Yannick Smits wrote:

> - 
> 
> ```
> Can we have query time index boost levels?
> 
> ```

Yes. Look at the Query DSL docs - most queries take a 'boost'  
parameter.

> - 
> 
> ```
> How would you implement formatting based boosting. For
> 
> ```
> 
> instance have bold, italic and uppercase texts (HTML) have higher  
> scores?

I don't think you can (at least not currently)

> - 
> 
> ```
> I noticed phrase searches actually don’t limit the search
> 
> ```
> 
> results in to matches in 1 phrase. So when searching for “fear of  
> dark” it will also match if fear and dark appear in different  
> sentences (“Then it became dark. He had fear of cats.”). Is there a  
> way to force the result to be in the same sentence?

I think you mean a 'text' query, not a 'text\_phrase' query. A text query will match text that contains the same words. A text\_phrase query will find text that includes exactly the same phrase (ignoring stop words like 'of').

You can set the slop factor for text\_phrase queries so that the words don't have to be right next to each other.

> - 
> 
> ```
> Is proximity of words also taken into account when doing a
> 
> ```
> 
> multi-word phrase search (the closer words appear the higher the  
> scoring?)

With the text\_phrase query, and slop, yes: proximity is taken into account.

clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [June 22, 2011, 2:23pm UTC](https://discuss.elastic.co/t/boost-scoring-and-phrase-search/4664/5 "2011-06-22T14:23:45Z")

</div>

Hi Yannick

> 1. I had a look at the docs but could not find a way to specify a  
> boost value based on indices the documents are in, at query time, only  
> as a configuration/static  
> ([Elastic — The Search AI Company | Elastic](http://www.elasticsearch.org/guide/reference/api/search/index-boost.html)). What am I missing?

The page you link to above does not say that indices\_boost is static -  
it is a parameter that you can pass to any search query.

curl -XGET '[http://127.0.0.1:9200/\_all/\_search?pretty=1](http://127.0.0.1:9200/_all/_search?pretty=1)' -d '  
{  
"query" : {  
"match\_all" : {}  
},  
"indices\_boost" : {  
"index\_foo" : 10,  
"index\_bar" : 1  
}  
}  
'

> 1. could you think of a strategy to simulate such a behavior? Like  
> extracting the bold words and saving them with a higher boost to a  
> different field or something without screwing up the highlighting  
> feature?

This would require some work on the client side. You could have two  
fields: 'text' and 'important\_text'. 'text' would contain all of the  
text, and 'important\_text' just the bits inside the **tags.**

 

Then you can use a bool query to boost anything found in important\_text,  
but only do the highlighting on the 'text' field.

> 1. yes, I'm using text\_phrase. But still I would like to know if it is  
> possible to have it look only within the phrase for the specified  
> terms instead of matching over multiple phrases.

ES has no concept of sentences. I thought of possibly breaking up the  
content into individual sentences, eg:

['The quick brown fox', 'jumped over the lazy dog']

but it looks like ES just concatenates these values anyway:

# [Wed Jun 22 16:22:35 2011] Protocol: http, Server: 192.168.5.103:9200

curl -XPOST '[http://127.0.0.1:9200/foo/bar?pretty=1](http://127.0.0.1:9200/foo/bar?pretty=1)' -d '  
{  
"text" : [  
"The quick brown fox",  
"jumped over the lazy dog"  
]  
}  
'

# [Wed Jun 22 16:22:35 2011] Response:

# {

# "ok" : true,

# "\_index" : "foo",

# "\_id" : "-Dt7zDUCQKauV69L\_32w9g",

# "\_type" : "bar",

# "\_version" : 1

# }

# [Wed Jun 22 16:22:49 2011] Protocol: http, Server: 192.168.5.103:9200

curl -XGET '[http://127.0.0.1:9200/foo/\_search?pretty=1](http://127.0.0.1:9200/foo/_search?pretty=1)' -d '  
{  
"query" : {  
"text\_phrase" : {  
"text" : "brown jumped"  
}  
}  
}  
'

# [Wed Jun 22 16:22:49 2011] Response:

# {

# "hits" : {

# "hits" : ,

# "max\_score" : null,

# "total" : 0

# },

# "timed\_out" : false,

# "\_shards" : {

# "failed" : 0,

# "successful" : 5,

# "total" : 5

# },

# "took" : 2

# }

# [Wed Jun 22 16:22:54 2011] Protocol: http, Server: 192.168.5.103:9200

curl -XGET '[http://127.0.0.1:9200/foo/\_search?pretty=1](http://127.0.0.1:9200/foo/_search?pretty=1)' -d '  
{  
"query" : {  
"text\_phrase" : {  
"text" : "fox jumped"  
}  
}  
}  
'

# [Wed Jun 22 16:22:54 2011] Response:

# {

# "hits" : {

# "hits" : [

# {

# "\_source" : {

# "text" : [

# "The quick brown fox",

# "jumped over the lazy dog"

# ]

# },

# "\_score" : 0.23013961,

# "\_index" : "foo",

# "\_id" : "-Dt7zDUCQKauV69L\_32w9g",

# "\_type" : "bar"

# }

# ],

# "max\_score" : 0.23013961,

# "total" : 1

# },

# "timed\_out" : false,

# "\_shards" : {

# "failed" : 0,

# "successful" : 5,

# "total" : 5

# },

# "took" : 2

# }

---

<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, 4:02am UTC](https://discuss.elastic.co/t/boost-scoring-and-phrase-search/4664/6 "2017-07-06T04:02:56Z")

</div>


