# Regarding Boosting

**URL:** <https://discuss.elastic.co/t/regarding-boosting/8989>\
**Category:** Elasticsearch\
**Created:** [September 11, 2012, 1:36pm UTC](https://discuss.elastic.co/t/regarding-boosting/8989 "2012-09-11T13:36:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andavar](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andavar](https://discuss.elastic.co/u/andavar)\
**Post date:** [September 11, 2012, 1:36pm UTC](https://discuss.elastic.co/t/regarding-boosting/8989/1 "2012-09-11T13:36:54Z")

</div>

Dear ElasticSearch Users,  
What is difference between index time boosting and Query time boosting.  
Here I am using query time boosting. Some scenario it will work fine. But most scenario it wont work.

My query is:  
{  
"field": {  
"my\_field": {  
"query": "dept1|Executive||dept2|Director||dept3|Individual",  
"analyzer": "myPipeAnalyzer",  
"boost": 1.4  
}  
}  
}

myPipeAnalyzer Settings:

{  
"index": {  
"analysis": {  
"analyzer": {  
"myPipeAnalyzer": {  
"type": "pattern",  
"flags": "DOTALL",  
"lowercase": "true",  
"pattern": "\|\|",  
"stopwords": "_none_"  
}  
}  
}  
}  
}

Please clarify why boosting wont work..

Thanks & Regards,  
Andavar

---

<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:** [September 11, 2012, 1:41pm UTC](https://discuss.elastic.co/t/regarding-boosting/8989/2 "2012-09-11T13:41:26Z")

</div>

On Tue, 2012-09-11 at 06:36 -0700, andavar wrote:

> Dear Elasticsearch Users,  
> What is difference between index time boosting and Query time  
> boosting.

It's just what it says. Index time boosting is set at index time. Query  
time boosting can be modified at query time.

> Here I am using query time boosting. Some scenario it will work fine. But  
> most scenario it wont work.

It's not obvious from your example what it is you want to achieve and  
why you think it's not working.

clint

> My query is:  
> {  
> "field": {  
> "my\_field": {  
> "query":  
> "dept1|Executive||dept2|Director||dept3|Individual",  
> "analyzer": "myPipeAnalyzer",  
> "boost": 1.4  
> }  
> }  
> }
> 
> myPipeAnalyzer Settings:
> 
> {  
> "index": {  
> "analysis": {  
> "analyzer": {  
> "myPipeAnalyzer": {  
> "type": "pattern",  
> "flags": "DOTALL",  
> "lowercase": "true",  
> "pattern": "\|\|",  
> "stopwords": "_none_"  
> }  
> }  
> }  
> }  
> }
> 
> Please clarify why boosting wont work..
> 
> Thanks & Regards,  
> Andavar
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Regarding-Boosting-tp4022608.html](http://elasticsearch-users.115913.n3.nabble.com/Regarding-Boosting-tp4022608.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![andavar](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andavar](https://discuss.elastic.co/u/andavar)\
**Post date:** [September 11, 2012, 3:15pm UTC](https://discuss.elastic.co/t/regarding-boosting/8989/3 "2012-09-11T15:15:15Z")

</div>

thanks Clint.

My query is:  
{  
"from": 0,  
"size": 25,  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"must": {  
"bool": {  
"should": [  
{  
"query\_string": {  
"query": "test",  
"default\_operator": "and"  
}  
}  
]  
}  
},  
 **"should": [  
{  
"term": {  
"myField1": {  
"value": true,  
"boost": 2.4  
}  
}  
},  
{  
"field": {  
"myField2": {  
"query": "dept1|Executive||dep2|Director/Manager||dept3|Individual",  
"analyzer": "myPipeAnalyzer",  
"boost": 1.4  
}  
}  
}  
]**  
}  
},  
"filter": {  
"and": {  
"filters": [  
{  
"term": {  
"myField3": true  
}  
},  
{  
"query": {  
"field": {  
"myField4": "ACT"  
}  
}  
}  
]  
}  
}  
}  
}  
}

In my query highlighted part for relevance related. myField1 value is true in some document and also myField2 value is"dept1|Executive||dep2|Director/Manager||dept3|Individual" like that.

Now I am searching using above mentioned query.

There are 3 scenario fetching the result.

1. If document have Myfield1 and myField2 with that value means, that documents comes top of the result. Because I applied boost 2 & 1.4.
2. If any one of that having means, it comes to next in result.
3. These fields values different means, it comes to last.

These scenario wont work for that query.

Is there any other way for achieved my scenario..

thanks,

---

<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:** [September 11, 2012, 4:11pm UTC](https://discuss.elastic.co/t/regarding-boosting/8989/4 "2012-09-11T16:11:16Z")

</div>

Hi Andavar

> 

There are 3 scenario fetching the result.

> 1. If document have Myfield1 and myField2 with that value means, that  
> documents comes top of the result. Because I applied boost 2 & 1.4.
> 2. If any one of that having means, it comes to next in result.
> 3. These fields values different means, it comes to last.
> 
> These scenario wont work for that query.

I'd propose doing it somewhat differently.

1. For myField1-4, those are filters, not queries. So store the data  
correctly and search them using filters. Filters perform better than  
queries and can be cached.

By "store the data correctly" I mean, eg: set the mapping for myField2  
to:  
{ type: "string", index: "not\_analyzed" }

which means that it index the exact value that you pass in  
(eg "dept2|Director/Manager") instead of analyzing the text and storing  
the terms that come from the analysis,  
eg ["dept2", "director", "manager].

You can index your docs with eg:  
{  
myField2: "dept2|Director/Manager"  
}

Or even multiple values:  
{  
myField2: ["dept1|Executive", "dept2|Director/Manager"]  
}

You don't need to use complicated pipe encoding hacks.

To run filters on that field, you should use a term/s filter rather than  
a query (see below).

(My solution below probably won't work yet, because your data needs to  
be reindexed after mapping the fields correctly).

1. The 'boost' values that you are using are not absolutes. Instead  
they get factored into the "relevance" score that elasticsearch  
calculates. This will depend on various factors, eg "how common is the  
term 'Executive'". That's not what you want. You're just saying "If a  
document has this field, then sort it higher".

So a better way to do that is to use the custom\_filters\_score 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" : {  
"custom\_filters\_score" : {  
"query" : {  
"filtered" : {  
"filter" : {  
"and" : [  
{  
"term" : {  
"myField3" : true  
}  
},  
{  
"term" : {  
"myField4" : "ACT"  
}  
}  
]  
},  
"query" : {  
"query\_string" : {  
"query" : "test",  
"default\_operator" : "and"  
}  
}  
}  
},  
"score\_mode" : "total",  
"filters" : [  
{  
"boost" : "2.4",  
"filter" : {  
"term" : {  
"myField1" : true  
}  
}  
},  
{  
"boost" : "1.4",  
"filter" : {  
"terms" : {  
"myField2" : [  
"dept1|Executive",  
"dept2|Director/Manager",  
"dept3|Individual"  
]  
}  
}  
}  
]  
}  
}  
}  
'

I'd have given you a gist showing all the steps, including the mapping  
etc, but you only included partial information in your email. The more  
info you give, the easier it is to answer a question. The best way is  
to provide a complete recreation in curl that we can just copy and paste  
to run.

See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help) for info about better ways to ask  
the question

hope this helps

clint

Note: "myField1" etc are bad names for fields. Give them meaningful  
names, so that we (and you) don't have to guess what they mean

--

---

<div class="post-metadata">

**Author:** ![andavar](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@andavar](https://discuss.elastic.co/u/andavar)\
**Post date:** [September 13, 2012, 1:06pm UTC](https://discuss.elastic.co/t/regarding-boosting/8989/5 "2012-09-13T13:06:45Z")

</div>

thanks Clinton,

---

<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:12am UTC](https://discuss.elastic.co/t/regarding-boosting/8989/6 "2017-07-06T03:12:54Z")

</div>


