# How to specify Field weights

**URL:** https://discuss.elastic.co/t/how-to-specify-field-weights/5279
**Category:** Elasticsearch
**Created:** [August 30, 2011, 10:21am UTC](https://discuss.elastic.co/t/how-to-specify-field-weights/5279 "2011-08-30T10:21:43Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Raul\_Jr\_Martinez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raul_jr_martinez/32/1286_2.png) [@Raul\_Jr\_Martinez](https://discuss.elastic.co/u/Raul_Jr_Martinez)
#### Post date: [August 30, 2011, 10:21am UTC](https://discuss.elastic.co/t/how-to-specify-field-weights/5279/1 "2011-08-30T10:21:43Z")

</div>

Hello to all,

I've been looking into putting weight on a select number of fields for my  
project. I thought that doing _fieldname^weight_ would work but it doesn't  
unfortunately. I know I read somewhere that using caret would do the  
tricky.

My main goal is to ensure that the relevancy algorithm would consider  
putting a lot of weight in keywords matching the _title_ than the \*contents

- fields.

Has anybody solved what I'm trying to do?

Thanks,

Raul

---

<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: [August 30, 2011, 10:48am UTC](https://discuss.elastic.co/t/how-to-specify-field-weights/5279/2 "2011-08-30T10:48:37Z")

</div>

Hi Raul

> I've been looking into putting weight on a select number of fields for  
> my project. I thought that doing fieldname^weight would work but it  
> doesn't unfortunately. I know I read somewhere that using caret would  
> do the tricky.
> 
> My main goal is to ensure that the relevancy algorithm would consider  
> putting a lot of weight in keywords matching the title than the  
> contents fields.

You can combine queries with the bool or dismax query, and give each  
query different weights, eg:

curl -XGET '[http://127.0.0.1:9200/\_all/\_search?pretty=1](http://127.0.0.1:9200/_all/_search?pretty=1)' -d '  
{  
"query" : {  
"dis\_max" : {  
"queries" : [  
{  
"text" : {  
"title" : {  
"boost" : 2,  
"query" : "keywords"  
}  
}  
},  
{  
"text" : {  
"content" : "keywords"  
}  
}  
]  
}  
}  
}  
'

---

<div class="post-metadata">

### Author: ![Raul\_Jr\_Martinez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raul_jr_martinez/32/1286_2.png) [@Raul\_Jr\_Martinez](https://discuss.elastic.co/u/Raul_Jr_Martinez)
#### Post date: [August 31, 2011, 4:45am UTC](https://discuss.elastic.co/t/how-to-specify-field-weights/5279/3 "2011-08-31T04:45:19Z")

</div>

Hi Clinton,

Thanks for the insight. I am using FuzzyLikeThis query so fields are defined  
as a group so the structure is a bit different. Having said, my initial  
strategy is to set the boost value of a field when defining the mapping. It  
seems to work just fine. I'm just looking for ways to set field weight at  
query-time for FLT queries specifically.

Thanks,  
RAUL

---

<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: [August 31, 2011, 7:38am UTC](https://discuss.elastic.co/t/how-to-specify-field-weights/5279/4 "2011-08-31T07:38:53Z")

</div>

Hi raul

> Thanks for the insight. I am using FuzzyLikeThis query so fields are  
> defined as a group so the structure is a bit different. Having said,  
> my initial strategy is to set the boost value of a field when defining  
> the mapping. It seems to work just fine. I'm just looking for ways to  
> set field weight at query-time for FLT queries specifically.

With the fuzzy-like-this query, you specify a list of fields, and you  
can specify the boost for each field as follows:

['title^3','tags^2', 'content']

clint

---

<div class="post-metadata">

### Author: ![Ciryus](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Ciryus](https://discuss.elastic.co/u/Ciryus)
#### Post date: [December 2, 2011, 2:17am UTC](https://discuss.elastic.co/t/how-to-specify-field-weights/5279/5 "2011-12-02T02:17:52Z")

</div>

Hi,

I'm running into the same issue. I wanted to make a AND query with  
different boosts for different fields. So let's say I'm searching across  
fields 'title' and 'body' the words 'foo' 'bar' 'baz'. I only want to  
return documents that have ALL words, but want to give a preference to the  
title. So for example: foo & bar in title and baz in body gets a higher  
score than only foo in title and bar & baz in body. But I don't want a  
document that would not have ALL the terms. Any idea?

Thanks!

---

<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, 3:46am UTC](https://discuss.elastic.co/t/how-to-specify-field-weights/5279/6 "2017-07-06T03:46:38Z")

</div>


