# Mapping/boosting problem

**URL:** <https://discuss.elastic.co/t/mapping-boosting-problem/8573>\
**Category:** Elasticsearch\
**Created:** [July 31, 2012, 6:50am UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573 "2012-07-31T06:50:33Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Uli\_Schimpfle](https://avatars.discourse-cdn.com/v4/letter/u/e5b9ba/32.png) [@Uli\_Schimpfle](https://discuss.elastic.co/u/Uli_Schimpfle)\
**Post date:** [July 31, 2012, 6:50am UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/1 "2012-07-31T06:50:33Z")

</div>

Hi,

I'm new to ElasticSearch/Lucene and I have a question about boosting.

I created a mapping which defines a "\_boost" field and I also have a  
"boost" property for one field of my two fields.  
If I understand it right with "\_boost" I define a boost for the document  
and with "boost" I define a boost for a field.

If I do a search the "\_score" fields of the hits have always the value 1.0.

Shouldn't have the \_score field different values than 1.0 (and so the  
sorting of the hits) ?

Please have a look at :

> <https://gist.github.com/uliSchi/3207478>

Thanks,

Uli

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 31, 2012, 10:31am UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/2 "2012-07-31T10:31:31Z")

</div>

Hi Uli,

Prefixquery and other multi-term queries (like wildcard query) don't  
compute scores by default (score is always 1). Actually the score is  
determined by the query time boost and the index time boost you  
specified isn't used.

However the scoring can be somewhat controlled by setting a rewrite method:

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

Perhaps setting rewrite parameter to: 'top\_terms\_10' gives the scores  
/ sorting you want.

Martijn

On 31 July 2012 08:50, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:

> Hi,
> 
> I'm new to Elasticsearch/Lucene and I have a question about boosting.
> 
> I created a mapping which defines a "\_boost" field and I also have a "boost"  
> property for one field of my two fields.  
> If I understand it right with "\_boost" I define a boost for the document and  
> with "boost" I define a boost for a field.
> 
> If I do a search the "\_score" fields of the hits have always the value 1.0.
> 
> Shouldn't have the \_score field different values than 1.0 (and so the  
> sorting of the hits) ?
> 
> Please have a look at :
> 
> [elasticsearch boost problem · GitHub](https://gist.github.com/3207478)
> 
> Thanks,
> 
> Uli

--  
Met vriendelijke groet,

Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![Uli\_Schimpfle](https://avatars.discourse-cdn.com/v4/letter/u/e5b9ba/32.png) [@Uli\_Schimpfle](https://discuss.elastic.co/u/Uli_Schimpfle)\
**Post date:** [July 31, 2012, 11:21am UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/3 "2012-07-31T11:21:05Z")

</div>

Hi Martijn,

Thanks for your answer about the multi-term queries. I didn't know that.

I tried to use the "rewrite": "top\_terms\_10" but it didn't help.

curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
"query": {  
"prefix": {  
"name": "Se",  
"rewrite": "top\_terms\_10"  
}  
}  
}'

May you have any suggestion what else I could do/try to get the boosting  
for the this. Filters?, Sorting?,... I need to do some search like a prefix  
query  
on multiple fields.

Thanks,

Uli

Am Dienstag, 31. Juli 2012 12:31:31 UTC+2 schrieb Martijn v Groningen:

> Hi Uli,
> 
> Prefixquery and other multi-term queries (like wildcard query) don't  
> compute scores by default (score is always 1). Actually the score is  
> determined by the query time boost and the index time boost you  
> specified isn't used.
> 
> However the scoring can be somewhat controlled by setting a rewrite  
> method:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/multi-term-rewrite.html)
> 
> Perhaps setting rewrite parameter to: 'top\_terms\_10' gives the scores  
> / sorting you want.
> 
> Martijn
> 
> On 31 July 2012 08:50, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:
> 
> > Hi,
> > 
> > I'm new to Elasticsearch/Lucene and I have a question about boosting.
> > 
> > I created a mapping which defines a "\_boost" field and I also have a  
> > "boost"  
> > property for one field of my two fields.  
> > If I understand it right with "\_boost" I define a boost for the document  
> > and  
> > with "boost" I define a boost for a field.
> > 
> > If I do a search the "\_score" fields of the hits have always the value  
> > 1.0.
> > 
> > Shouldn't have the \_score field different values than 1.0 (and so the  
> > sorting of the hits) ?
> > 
> > Please have a look at :
> > 
> > [elasticsearch boost problem · GitHub](https://gist.github.com/3207478)
> > 
> > Thanks,
> > 
> > Uli
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 31, 2012, 11:59am UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/4 "2012-07-31T11:59:33Z")

</div>

Hi Uli,

The query you specified is incorrect. The query should be:  
curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
"query": {  
"prefix": {  
"name": {  
"value" : "Se",  
"rewrite": "top\_terms\_10"  
}  
}  
}  
}'

This query does the boost into account.

Martijn

On 31 July 2012 13:21, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:

> Hi Martijn,
> 
> Thanks for your answer about the multi-term queries. I didn't know that.
> 
> I tried to use the "rewrite": "top\_terms\_10" but it didn't help.
> 
> curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
> "query": {  
> "prefix": {  
> "name": "Se",  
> "rewrite": "top\_terms\_10"  
> }  
> }  
> }'
> 
> May you have any suggestion what else I could do/try to get the boosting  
> for the this. Filters?, Sorting?,... I need to do some search like a prefix  
> query  
> on multiple fields.
> 
> Thanks,
> 
> Uli
> 
> Am Dienstag, 31. Juli 2012 12:31:31 UTC+2 schrieb Martijn v Groningen:
> 
> > Hi Uli,
> > 
> > Prefixquery and other multi-term queries (like wildcard query) don't  
> > compute scores by default (score is always 1). Actually the score is  
> > determined by the query time boost and the index time boost you  
> > specified isn't used.
> > 
> > However the scoring can be somewhat controlled by setting a rewrite  
> > method:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/multi-term-rewrite.html)
> > 
> > Perhaps setting rewrite parameter to: 'top\_terms\_10' gives the scores  
> > / sorting you want.
> > 
> > Martijn
> > 
> > On 31 July 2012 08:50, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:
> > 
> > > Hi,
> > > 
> > > I'm new to Elasticsearch/Lucene and I have a question about boosting.
> > > 
> > > I created a mapping which defines a "\_boost" field and I also have a  
> > > "boost"  
> > > property for one field of my two fields.  
> > > If I understand it right with "\_boost" I define a boost for the document  
> > > and  
> > > with "boost" I define a boost for a field.
> > > 
> > > If I do a search the "\_score" fields of the hits have always the value  
> > > 1.0.
> > > 
> > > Shouldn't have the \_score field different values than 1.0 (and so the  
> > > sorting of the hits) ?
> > > 
> > > Please have a look at :
> > > 
> > > [elasticsearch boost problem · GitHub](https://gist.github.com/3207478)
> > > 
> > > Thanks,
> > > 
> > > Uli
> > 
> > --  
> > Met vriendelijke groet,
> > 
> > Martijn van Groningen

--  
Met vriendelijke groet,

Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![Uli\_Schimpfle](https://avatars.discourse-cdn.com/v4/letter/u/e5b9ba/32.png) [@Uli\_Schimpfle](https://discuss.elastic.co/u/Uli_Schimpfle)\
**Post date:** [July 31, 2012, 12:09pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/5 "2012-07-31T12:09:34Z")

</div>

Hi Martijn,

Thanks a lot!  
Wouldn't have thought that the query was incorrect...

Now the result to sorted correctly. At least for document boosting.  
But if I change the boosting of the field (in the mapping) the score values  
are still the same.  
I'm now searching in "\_all" fields

curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
"query": {  
"prefix": {  
"\_all": {  
"value": "se",  
"rewrite": "top\_terms\_10"  
}  
}  
}  
}'

Do you have an idea how to fix this? Do I have to split up the query in  
multiple  
ones for each field and define there a boosting?

Thanks,

Uli

Am Dienstag, 31. Juli 2012 13:59:33 UTC+2 schrieb Martijn v Groningen:

> Hi Uli,
> 
> The query you specified is incorrect. The query should be:  
> curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
> "query": {  
> "prefix": {  
> "name": {  
> "value" : "Se",  
> "rewrite": "top\_terms\_10"  
> }  
> }  
> }  
> }'
> 
> This query does the boost into account.
> 
> Martijn
> 
> On 31 July 2012 13:21, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:
> 
> > Hi Martijn,
> > 
> > Thanks for your answer about the multi-term queries. I didn't know that.
> > 
> > I tried to use the "rewrite": "top\_terms\_10" but it didn't help.
> > 
> > curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
> > "query": {  
> > "prefix": {  
> > "name": "Se",  
> > "rewrite": "top\_terms\_10"  
> > }  
> > }  
> > }'
> > 
> > May you have any suggestion what else I could do/try to get the boosting  
> > for the this. Filters?, Sorting?,... I need to do some search like a  
> > prefix  
> > query  
> > on multiple fields.
> > 
> > Thanks,
> > 
> > Uli
> > 
> > Am Dienstag, 31. Juli 2012 12:31:31 UTC+2 schrieb Martijn v Groningen:
> > 
> > > Hi Uli,
> > > 
> > > Prefixquery and other multi-term queries (like wildcard query) don't  
> > > compute scores by default (score is always 1). Actually the score is  
> > > determined by the query time boost and the index time boost you  
> > > specified isn't used.
> > > 
> > > However the scoring can be somewhat controlled by setting a rewrite  
> > > method:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/multi-term-rewrite.html)
> 
> > > Perhaps setting rewrite parameter to: 'top\_terms\_10' gives the scores  
> > > / sorting you want.
> > > 
> > > Martijn
> > > 
> > > On 31 July 2012 08:50, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com)  
> > > wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I'm new to Elasticsearch/Lucene and I have a question about boosting.
> > > > 
> > > > I created a mapping which defines a "\_boost" field and I also have a  
> > > > "boost"  
> > > > property for one field of my two fields.  
> > > > If I understand it right with "\_boost" I define a boost for the  
> > > > document  
> > > > and  
> > > > with "boost" I define a boost for a field.
> > > > 
> > > > If I do a search the "\_score" fields of the hits have always the  
> > > > value  
> > > > 1.0.
> > > > 
> > > > Shouldn't have the \_score field different values than 1.0 (and so the  
> > > > sorting of the hits) ?
> > > > 
> > > > Please have a look at :
> > > > 
> > > > [elasticsearch boost problem · GitHub](https://gist.github.com/3207478)
> > > > 
> > > > Thanks,
> > > > 
> > > > Uli
> > > 
> > > --  
> > > Met vriendelijke groet,
> > > 
> > > Martijn van Groningen
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 31, 2012, 12:22pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/6 "2012-07-31T12:22:27Z")

</div>

You only changed the \_boosting field in the mapping? Did you reindex?

The boost value you set in boostFactor applies for the whole doc as  
far as I know.  
So doesn't matter what field you query (\_all, name etc) as long as  
there is a hit, the  
boost should be applied.

Martijn

On 31 July 2012 14:09, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:

> Hi Martijn,
> 
> Thanks a lot!  
> Wouldn't have thought that the query was incorrect...
> 
> Now the result to sorted correctly. At least for document boosting.  
> But if I change the boosting of the field (in the mapping) the score values  
> are still the same.  
> I'm now searching in "\_all" fields
> 
> curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
> "query": {  
> "prefix": {  
> "\_all": {  
> "value": "se",  
> "rewrite": "top\_terms\_10"  
> }  
> }  
> }  
> }'
> 
> Do you have an idea how to fix this? Do I have to split up the query in  
> multiple  
> ones for each field and define there a boosting?
> 
> Thanks,
> 
> Uli
> 
> Am Dienstag, 31. Juli 2012 13:59:33 UTC+2 schrieb Martijn v Groningen:
> 
> > Hi Uli,
> > 
> > The query you specified is incorrect. The query should be:  
> > curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
> > "query": {  
> > "prefix": {  
> > "name": {  
> > "value" : "Se",  
> > "rewrite": "top\_terms\_10"  
> > }  
> > }  
> > }  
> > }'
> > 
> > This query does the boost into account.
> > 
> > Martijn
> > 
> > On 31 July 2012 13:21, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:
> > 
> > > Hi Martijn,
> > > 
> > > Thanks for your answer about the multi-term queries. I didn't know that.
> > > 
> > > I tried to use the "rewrite": "top\_terms\_10" but it didn't help.
> > > 
> > > curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
> > > "query": {  
> > > "prefix": {  
> > > "name": "Se",  
> > > "rewrite": "top\_terms\_10"  
> > > }  
> > > }  
> > > }'
> > > 
> > > May you have any suggestion what else I could do/try to get the boosting  
> > > for the this. Filters?, Sorting?,... I need to do some search like a  
> > > prefix  
> > > query  
> > > on multiple fields.
> > > 
> > > Thanks,
> > > 
> > > Uli
> > > 
> > > Am Dienstag, 31. Juli 2012 12:31:31 UTC+2 schrieb Martijn v Groningen:
> > > 
> > > > Hi Uli,
> > > > 
> > > > Prefixquery and other multi-term queries (like wildcard query) don't  
> > > > compute scores by default (score is always 1). Actually the score is  
> > > > determined by the query time boost and the index time boost you  
> > > > specified isn't used.
> > > > 
> > > > However the scoring can be somewhat controlled by setting a rewrite  
> > > > method:
> > > > 
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/multi-term-rewrite.html)
> > > > 
> > > > Perhaps setting rewrite parameter to: 'top\_terms\_10' gives the scores  
> > > > / sorting you want.
> > > > 
> > > > Martijn
> > > > 
> > > > On 31 July 2012 08:50, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com)  
> > > > wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > I'm new to Elasticsearch/Lucene and I have a question about boosting.
> > > > > 
> > > > > I created a mapping which defines a "\_boost" field and I also have a  
> > > > > "boost"  
> > > > > property for one field of my two fields.  
> > > > > If I understand it right with "\_boost" I define a boost for the  
> > > > > document  
> > > > > and  
> > > > > with "boost" I define a boost for a field.
> > > > > 
> > > > > If I do a search the "\_score" fields of the hits have always the  
> > > > > value  
> > > > > 1.0.
> > > > > 
> > > > > Shouldn't have the \_score field different values than 1.0 (and so the  
> > > > > sorting of the hits) ?
> > > > > 
> > > > > Please have a look at :
> > > > > 
> > > > > [elasticsearch boost problem · GitHub](https://gist.github.com/3207478)
> > > > > 
> > > > > Thanks,
> > > > > 
> > > > > Uli
> > > > 
> > > > --  
> > > > Met vriendelijke groet,
> > > > 
> > > > Martijn van Groningen
> > 
> > --  
> > Met vriendelijke groet,
> > 
> > Martijn van Groningen

--  
Met vriendelijke groet,

Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![Uli\_Schimpfle](https://avatars.discourse-cdn.com/v4/letter/u/e5b9ba/32.png) [@Uli\_Schimpfle](https://discuss.elastic.co/u/Uli_Schimpfle)\
**Post date:** [July 31, 2012, 12:47pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/7 "2012-07-31T12:47:31Z")

</div>

In my little test script at the beginning I delete the index, create a new  
one,  
write the mapping, write the documents.

First try (with a field boost factor of 20) :

curl -XPUT '[http://localhost:9200/myindex/author/\_mapping](http://localhost:9200/myindex/author/_mapping)' -d '{  
"author": {  
"\_boost": {  
"name": "boostFactor",  
"null\_value": 1.0  
},  
"properties": {  
"id": {  
"type": "long"  
},  
"boostFactor": {  
"type": "float",  
"null\_value": 1.0  
},  
"name": {  
"type": "string",  
"index": "not\_analyzed",  
"boost": 20.0  
},  
"countryOfBirth": {  
"type": "string"  
}  
}  
}  
}'

The result is :  
..."\_score":0.076713204,"\_source":{"id":2,"boostFactor":0.61,"name":"Sergio  
Herold","countryOfBirth":"Peru"}}  
..."\_score":0.033562027,"\_source":{"id":1,"boostFactor":0.22,"name":"Sewald  
Kruse","countryOfBirth":"Deutschland"}}  
..."\_score":0.009589151,"\_source":{"id":4,"boostFactor":0.07,"name":"Gudrun  
Weil","countryOfBirth":"Serbien"}}  
..."\_score":0.0041952534,"\_source":{"id":3,"boostFactor":0.03,"name":"Sebastion  
Wund","countryOfBirth":"Deutschland"}}

Please have a look at the 3rd line. The query value was found in the  
"countryOfBirth" field.

Now with a boosting value of 1 :

curl -XPUT '[http://localhost:9200/myindex/author/\_mapping](http://localhost:9200/myindex/author/_mapping)' -d '{  
"author": {  
"\_boost": {  
"name": "boostFactor",  
"null\_value": 1.0  
},  
"properties": {  
"id": {  
"type": "long"  
},  
"boostFactor": {  
"type": "float",  
"null\_value": 1.0  
},  
"name": {  
"type": "string",  
"index": "not\_analyzed",  
"boost": 1.0  
},  
"countryOfBirth": {  
"type": "string"  
}  
}  
}  
}'

The result is :  
..."\_score":0.076713204,"\_source":{"id":2,"boostFactor":0.61,"name":"Sergio  
Herold","countryOfBirth":"Peru"}}  
..."\_score":0.033562027,"\_source":{"id":1,"boostFactor":0.22,"name":"Sewald  
Kruse","countryOfBirth":"Deutschland"}}  
..."\_score":0.009589151,"\_source":{"id":4,"boostFactor":0.07,"name":"Gudrun  
Weil","countryOfBirth":"Serbien"}}  
..."\_score":0.0041952534,"\_source":{"id":3,"boostFactor":0.03,"name":"Sebastion  
Wund","countryOfBirth":"Deutschland"}}

As you can see the \_score values are the same. Shouldn't there be a  
difference between the row 3 and the rows 1,2,4 ?

If I change the field "boostFactor" of the documents I get different \_sorce  
values. But not if I change the boosting  
in the mapping for the field "name"...

Any suggestions?

Thanks,

Uli

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 1, 2012, 9:07am UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/8 "2012-08-01T09:07:05Z")

</div>

Hi Uli,

I'd expect a difference to. I tried to reproduce the issue you're  
experience. However on my machine here it seems to work  
as expected.

I first run your script as in specified in the gist and I get the  
following result:  
[{"\_index":"myindex","\_type":"author","\_id":"2","\_score":3.6822338,  
"\_source" : {  
"id": 2,  
"boostFactor": 0.61,  
"name": "Sergio Herold",  
"countryOfBirth": "Peru"  
}},{"\_index":"myindex","\_type":"author","\_id":"1","\_score":1.2274113,  
"\_source" : {  
"id": 1,  
"boostFactor": 0.22,  
"name": "Sewald Kruse",  
"countryOfBirth": "Deutschland"  
}},{"\_index":"myindex","\_type":"author","\_id":"3","\_score":0.15342641,  
"\_source" : {  
"id": 3,  
"boostFactor": 0.03,  
"name": "Sebastion Wund",  
"countryOfBirth": "Deutschland"  
}}]

I then change the mapping in the script and re-execute it with the  
following result:  
[{"\_index":"myindex","\_type":"author","\_id":"2","\_score":0.15342641,  
"\_source" : {  
"id": 2,  
"boostFactor": 0.61,  
"name": "Sergio Herold",  
"countryOfBirth": "Peru"  
}},{"\_index":"myindex","\_type":"author","\_id":"1","\_score":0.067124054,  
"\_source" : {  
"id": 1,  
"boostFactor": 0.22,  
"name": "Sewald Kruse",  
"countryOfBirth": "Deutschland"  
}},{"\_index":"myindex","\_type":"author","\_id":"3","\_score":0.008390507,  
"\_source" : {  
"id": 3,  
"boostFactor": 0.03,  
"name": "Sebastion Wund",  
"countryOfBirth": "Deutschland"  
}}]

As you can the \_score values are different.

Martijn

On 31 July 2012 14:47, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:

> In my little test script at the beginning I delete the index, create a new  
> one,  
> write the mapping, write the documents.
> 
> First try (with a field boost factor of 20) :
> 
> curl -XPUT '[http://localhost:9200/myindex/author/\_mapping](http://localhost:9200/myindex/author/_mapping)' -d '{  
> "author": {  
> "\_boost": {  
> "name": "boostFactor",  
> "null\_value": 1.0  
> },  
> "properties": {  
> "id": {  
> "type": "long"  
> },  
> "boostFactor": {  
> "type": "float",  
> "null\_value": 1.0  
> },  
> "name": {  
> "type": "string",  
> "index": "not\_analyzed",  
> "boost": 20.0  
> },  
> "countryOfBirth": {  
> "type": "string"  
> }  
> }  
> }  
> }'
> 
> The result is :  
> ..."\_score":0.076713204,"\_source":{"id":2,"boostFactor":0.61,"name":"Sergio  
> Herold","countryOfBirth":"Peru"}}  
> ..."\_score":0.033562027,"\_source":{"id":1,"boostFactor":0.22,"name":"Sewald  
> Kruse","countryOfBirth":"Deutschland"}}  
> ..."\_score":0.009589151,"\_source":{"id":4,"boostFactor":0.07,"name":"Gudrun  
> Weil","countryOfBirth":"Serbien"}}  
> ..."\_score":0.0041952534,"\_source":{"id":3,"boostFactor":0.03,"name":"Sebastion  
> Wund","countryOfBirth":"Deutschland"}}
> 
> Please have a look at the 3rd line. The query value was found in the  
> "countryOfBirth" field.
> 
> Now with a boosting value of 1 :
> 
> curl -XPUT '[http://localhost:9200/myindex/author/\_mapping](http://localhost:9200/myindex/author/_mapping)' -d '{  
> "author": {  
> "\_boost": {  
> "name": "boostFactor",  
> "null\_value": 1.0  
> },  
> "properties": {  
> "id": {  
> "type": "long"  
> },  
> "boostFactor": {  
> "type": "float",  
> "null\_value": 1.0  
> },  
> "name": {  
> "type": "string",  
> "index": "not\_analyzed",  
> "boost": 1.0  
> },  
> "countryOfBirth": {  
> "type": "string"  
> }  
> }  
> }  
> }'
> 
> The result is :  
> ..."\_score":0.076713204,"\_source":{"id":2,"boostFactor":0.61,"name":"Sergio  
> Herold","countryOfBirth":"Peru"}}  
> ..."\_score":0.033562027,"\_source":{"id":1,"boostFactor":0.22,"name":"Sewald  
> Kruse","countryOfBirth":"Deutschland"}}  
> ..."\_score":0.009589151,"\_source":{"id":4,"boostFactor":0.07,"name":"Gudrun  
> Weil","countryOfBirth":"Serbien"}}  
> ..."\_score":0.0041952534,"\_source":{"id":3,"boostFactor":0.03,"name":"Sebastion  
> Wund","countryOfBirth":"Deutschland"}}
> 
> As you can see the \_score values are the same. Shouldn't there be a  
> difference between the row 3 and the rows 1,2,4 ?
> 
> If I change the field "boostFactor" of the documents I get different \_sorce  
> values. But not if I change the boosting  
> in the mapping for the field "name"...
> 
> Any suggestions?
> 
> Thanks,
> 
> Uli

--  
Met vriendelijke groet,

Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![Uli\_Schimpfle](https://avatars.discourse-cdn.com/v4/letter/u/e5b9ba/32.png) [@Uli\_Schimpfle](https://discuss.elastic.co/u/Uli_Schimpfle)\
**Post date:** [August 1, 2012, 1:15pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/9 "2012-08-01T13:15:01Z")

</div>

Hi Martijn,

Thanks again for you answer.  
And you're right. The \_score values are different. It's my fault, I was  
(already) doing a different search.

curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
"query": {  
"prefix": {  
"\_all": {  
"value": "se",  
"rewrite": "top\_terms\_10"  
}  
}  
}

I change the field name to "\_all" (and the search string is now lowercase).  
Doing a search with "\_all" the scores don't change if I change the "boost"  
field of the "name" field in the mapping.

For now I'm doing some query like this :

curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
"query": {  
"custom\_score": {  
"query": {  
"query\_string": {  
"query": "name:(su\*)^20 su\*"  
}  
},  
"script": "\_score \* doc['boostFactor'].value"  
}  
}  
}'

This is probably not the fastet one...

Any suggestions for improvements ?

Thanks,

Uli

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 1, 2012, 1:53pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/10 "2012-08-01T13:53:01Z")

</div>

> I change the field name to "\_all" (and the search string is now lowercase).  
> Doing a search with "\_all" the scores don't change if I change the "boost"  
> field of the "name" field in the mapping.  
> After you've updated your mapping, do you see that your mapping has changed?  
> (by executing something like this: curl -XGET  
> '[http://localhost:9200/myindex/author/\_mapping](http://localhost:9200/myindex/author/_mapping)')

> curl -XGET '[http://localhost:9200/myindex/author/\_search](http://localhost:9200/myindex/author/_search)' -d '{  
> "query": {  
> "custom\_score": {  
> "query": {  
> "query\_string": {  
> "query": "name:(su\*)^20 su\*"  
> }  
> },  
> "script": "\_score \* doc['boostFactor'].value"  
> }  
> }  
> }'
> 
> This is probably not the fastet one...
> 
> Any suggestions for improvements ?  
> This can possible be an expensive query to execute, because the script  
> is execute for each hit in your whole result set.  
> On the other hand this query is more flexible, since it allows you to  
> tweak the result ordering without a reindex.  
> If your result set are very large this might not be the best way to  
> score you result and you might have to resort to index time boosting,  
> which is many times faster. Obviously this depends on your data and  
> queries.

Martijn

---

<div class="post-metadata">

**Author:** ![Uli\_Schimpfle](https://avatars.discourse-cdn.com/v4/letter/u/e5b9ba/32.png) [@Uli\_Schimpfle](https://discuss.elastic.co/u/Uli_Schimpfle)\
**Post date:** [August 1, 2012, 3:00pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/11 "2012-08-01T15:00:12Z")

</div>

> After you've updated your mapping, do you see that your mapping has  
> changed?

> (by executing something like this: curl -XGET  
> '[http://localhost:9200/myindex/author/\_mapping](http://localhost:9200/myindex/author/_mapping)')

It showed me the correct result. One time the value 20 for the "boost" and  
one time e.g. 2

I posted another gist with the changed query and the additional mapping  
query :

> <https://gist.github.com/uliSchi/3227493>

> This can possible be an expensive query to execute, because the script

> is execute for each hit in your whole result set.  
> On the other hand this query is more flexible, since it allows you to  
> tweak the result ordering without a reindex.  
> If your result set are very large this might not be the best way to  
> score you result and you might have to resort to index time boosting,  
> which is many times faster. Obviously this depends on your data and  
> queries.

The index could get quite big. We have about 5 million documents (book  
titiles).  
And since I just started with Elasticsearch I'm more than welcome to hear  
about  
any improvments I can do...

Thanks,

Uli

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 2, 2012, 1:54pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/12 "2012-08-02T13:54:44Z")

</div>

Hi Uli,

After you updated the mapping (setting boost to 2 for field name) did  
you reindex the documents, right?  
I'm not sure if you did this... Alternatively you could also use the  
update api, to just update the names.

Martijn

On 1 August 2012 17:00, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:

> > After you've updated your mapping, do you see that your mapping has  
> > changed?
> > 
> > (by executing something like this: curl -XGET  
> > '[http://localhost:9200/myindex/author/\_mapping](http://localhost:9200/myindex/author/_mapping)')
> 
> It showed me the correct result. One time the value 20 for the "boost" and  
> one time e.g. 2
> 
> I posted another gist with the changed query and the additional mapping  
> query :  
> [elasticsearch boost problem 2 · GitHub](https://gist.github.com/3227493)
> 
> > This can possible be an expensive query to execute, because the script
> > 
> > is execute for each hit in your whole result set.  
> > On the other hand this query is more flexible, since it allows you to  
> > tweak the result ordering without a reindex.  
> > If your result set are very large this might not be the best way to  
> > score you result and you might have to resort to index time boosting,  
> > which is many times faster. Obviously this depends on your data and  
> > queries.
> 
> The index could get quite big. We have about 5 million documents (book  
> titiles).  
> And since I just started with Elasticsearch I'm more than welcome to hear  
> about  
> any improvments I can do...
> 
> Thanks,
> 
> Uli

--  
Met vriendelijke groet,

Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![Uli\_Schimpfle](https://avatars.discourse-cdn.com/v4/letter/u/e5b9ba/32.png) [@Uli\_Schimpfle](https://discuss.elastic.co/u/Uli_Schimpfle)\
**Post date:** [August 2, 2012, 2:31pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/13 "2012-08-02T14:31:46Z")

</div>

Hi Martijn,

I'm using my little script I posted (see the gist...)  
In this script I always delete the (old) index and creates a new one (with  
a new mapping).  
So the mapping/index should be always up-to-date.

Uli

Am Donnerstag, 2. August 2012 15:54:44 UTC+2 schrieb Martijn v Groningen:

> Hi Uli,
> 
> After you updated the mapping (setting boost to 2 for field name) did  
> you reindex the documents, right?  
> I'm not sure if you did this... Alternatively you could also use the  
> update api, to just update the names.
> 
> Martijn
> 
> On 1 August 2012 17:00, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:
> 
> > > After you've updated your mapping, do you see that your mapping has  
> > > changed?
> > > 
> > > (by executing something like this: curl -XGET  
> > > '[http://localhost:9200/myindex/author/\_mapping](http://localhost:9200/myindex/author/_mapping)')
> > 
> > It showed me the correct result. One time the value 20 for the "boost"  
> > and  
> > one time e.g. 2
> > 
> > I posted another gist with the changed query and the additional mapping  
> > query :  
> > [elasticsearch boost problem 2 · GitHub](https://gist.github.com/3227493)
> > 
> > > This can possible be an expensive query to execute, because the script
> > > 
> > > is execute for each hit in your whole result set.  
> > > On the other hand this query is more flexible, since it allows you to  
> > > tweak the result ordering without a reindex.  
> > > If your result set are very large this might not be the best way to  
> > > score you result and you might have to resort to index time boosting,  
> > > which is many times faster. Obviously this depends on your data and  
> > > queries.
> > 
> > The index could get quite big. We have about 5 million documents (book  
> > titiles).  
> > And since I just started with Elasticsearch I'm more than welcome to  
> > hear  
> > about  
> > any improvments I can do...
> > 
> > Thanks,
> > 
> > Uli
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 2, 2012, 4:48pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/14 "2012-08-02T16:48:19Z")

</div>

Hi Uli,

The reason the score stay the same is that you change the boosting for  
name but you search using the \_all field.  
For the \_all field the following boosting applies:  
"\_boost": {  
"name": "boostFactor",  
"null\_value": 1.0  
},

I assume you want give documents with hits name a higher boost, right?  
Perhaps this best achieved with just query  
time boosting using the custom boost factor query:

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

And then add the two queries together like this:  
{  
"query":{  
"bool":{  
"should":[  
{  
"prefix":{  
"\_all":{  
"value":"se",  
"rewrite":"top\_terms\_10"  
}  
}  
},  
{  
"custom\_boost\_factor":{  
"prefix":{  
"name":{  
"value":"se",  
"rewrite":"top\_terms\_10"  
}  
},  
"boost\_factor":20.0  
}  
}  
],  
"minimum\_number\_should\_match":1,  
"boost":1.0  
}

```
}

```

}

Martijn

On 2 August 2012 16:31, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:

> Hi Martijn,
> 
> I'm using my little script I posted (see the gist...)  
> In this script I always delete the (old) index and creates a new one (with a  
> new mapping).  
> So the mapping/index should be always up-to-date.
> 
> Uli
> 
> Am Donnerstag, 2. August 2012 15:54:44 UTC+2 schrieb Martijn v Groningen:
> 
> > Hi Uli,
> > 
> > After you updated the mapping (setting boost to 2 for field name) did  
> > you reindex the documents, right?  
> > I'm not sure if you did this... Alternatively you could also use the  
> > update api, to just update the names.
> > 
> > Martijn
> > 
> > On 1 August 2012 17:00, Uli Schimpfle [huschimpfle@googlemail.com](mailto:huschimpfle@googlemail.com) wrote:
> > 
> > > > After you've updated your mapping, do you see that your mapping has  
> > > > changed?
> > > > 
> > > > (by executing something like this: curl -XGET  
> > > > '[http://localhost:9200/myindex/author/\_mapping](http://localhost:9200/myindex/author/_mapping)')
> > > 
> > > It showed me the correct result. One time the value 20 for the "boost"  
> > > and  
> > > one time e.g. 2
> > > 
> > > I posted another gist with the changed query and the additional mapping  
> > > query :  
> > > [elasticsearch boost problem 2 · GitHub](https://gist.github.com/3227493)
> > > 
> > > > This can possible be an expensive query to execute, because the script
> > > > 
> > > > is execute for each hit in your whole result set.  
> > > > On the other hand this query is more flexible, since it allows you to  
> > > > tweak the result ordering without a reindex.  
> > > > If your result set are very large this might not be the best way to  
> > > > score you result and you might have to resort to index time boosting,  
> > > > which is many times faster. Obviously this depends on your data and  
> > > > queries.
> > > 
> > > The index could get quite big. We have about 5 million documents (book  
> > > titiles).  
> > > And since I just started with Elasticsearch I'm more than welcome to  
> > > hear  
> > > about  
> > > any improvments I can do...
> > > 
> > > Thanks,
> > > 
> > > Uli
> > 
> > --  
> > Met vriendelijke groet,
> > 
> > Martijn van Groningen

--  
Met vriendelijke groet,

Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![Arvinth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arvinth/32/1650_2.png) [@Arvinth](https://discuss.elastic.co/u/Arvinth)\
**Post date:** [April 16, 2014, 12:05pm UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/15 "2014-04-16T12:05:34Z")

</div>

Hi Martijn,

Can you please tell me how to do the same in a query string query without any fields specified. Using rewrite as a parameter here doesn't seem to work for me.

Can you provide me with an example?

---

<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:35am UTC](https://discuss.elastic.co/t/mapping-boosting-problem/8573/16 "2017-07-06T01:35:32Z")

</div>


