# Need suggestion: How to boost specific documents for a given search term

**URL:** <https://discuss.elastic.co/t/need-suggestion-how-to-boost-specific-documents-for-a-given-search-term/23441>\
**Category:** Elasticsearch\
**Created:** [April 28, 2015, 3:01pm UTC](https://discuss.elastic.co/t/need-suggestion-how-to-boost-specific-documents-for-a-given-search-term/23441 "2015-04-28T15:01:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [April 28, 2015, 3:01pm UTC](https://discuss.elastic.co/t/need-suggestion-how-to-boost-specific-documents-for-a-given-search-term/23441/1 "2015-04-28T15:01:40Z")

</div>

Hi ES experts,

I need your help on index design for a real scenario. It might be a long  
question, let me try explain it as concise as possible.

We are building a search engine to provide site search for our customers,  
the document in index could be something like this:

{ "Path":"[http://www.foo.com/doc/abc/1](http://www.foo.com/doc/abc/1)", "Title":"Title 1",  
"Description":"The description of doc 1", ... }  
{ "Path":"[http://www.foo.com/doc/abc/2](http://www.foo.com/doc/abc/2)", "Title":"Title 2",  
"Description":"The description of doc 2", ... }  
{ "Path":"[http://www.foo.com/doc/abc/3](http://www.foo.com/doc/abc/3)", "Title":"Title 3",  
"Description":"The description of doc 3", ... }  
...

For each query, the returned hit documents are by default sorted by  
relevance, but our customer also wants to _boost some specific documents  
for some keywords,_  
They will give us the following like boosting configuration XML:

 http://www.foo.com/doc/abc/1 http://www.foo.com/doc/abc/2 http://www.foo.com/doc/abc/1 http://www.foo.com/doc/abc/3 http://www.foo.com/doc/abc/2 http://www.foo.com/doc/abc/1

That mean, if user search “keyword1", the top 1 hit document should be the  
document whose Path field value is "[http://www.foo.com/doc/abc/1](http://www.foo.com/doc/abc/1)",  
regardless the relevance score of that document. Similarly, if search  
"keyword3", the top 3 hit documents should be  
"[http://www.foo.com/doc/abc/3](http://www.foo.com/doc/abc/3)", "[http://www.foo.com/doc/abc/2](http://www.foo.com/doc/abc/2)" and  
"[http://www.foo.com/doc/abc/1](http://www.foo.com/doc/abc/1)" respectively.

To satisfy this special requirement, my design is, firstly invert the  
original boosting XML to following format:  
  
  
  
  
  
  
  
  
  
  
  
\<keyword value="keyword3" rank=9900" /\>

Then add a nested field "Boost", which contains a list of keyword/rank  
field, to the document as following example:  
{  
"Boost": [  
{ "keyword":"keyword1", "rank": 10000},  
{ "keyword":"keyword2", "rank": 9900},  
{ "keyword":"keyword3", "rank": 9800}  
]  
"Path":"[http://www.foo.com/doc/abc/1](http://www.foo.com/doc/abc/1)",  
"Title":"Title 1",  
"Description":"The description of doc 1",  
...  
}

{  
"Boost": [  
{ "keyword":"keyword2", "rank": 10000},  
{ "keyword":"keyword3", "rank": 9900}  
]  
"Path":"[http://www.foo.com/doc/abc/2](http://www.foo.com/doc/abc/2)",  
"Title":"Title 2",  
"Description":"The description of doc 2",  
...  
}

{  
"Boost": [  
{ "keyword":"keyword3", "rank": 10000}  
]  
"Path":"[http://www.foo.com/doc/abc/3](http://www.foo.com/doc/abc/3)",  
"Title":"Title 3",  
"Description":"The description of doc 3",  
...  
}

Then in query time, use nested query to get the rank value of each matched  
document for a given search keyword, and use the score script to adjust the  
relevance score by the rank value. Since the rank value from boosting XML  
is much larger than normal relevance score ( generally less than 5), the  
adjusted score of the documents which configured in boosting XML for given  
keyword should be top scores.

Does this design work well? Any suggestions to better design?

Thanks in advance!

--  
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/3eb89d0f-b9a4-4d84-bc04-e0c764b9e314%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3eb89d0f-b9a4-4d84-bc04-e0c764b9e314%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Youxu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/youxu/32/117375_2.png) [@Youxu](https://discuss.elastic.co/u/Youxu)\
**Post date:** [April 30, 2015, 5:57am UTC](https://discuss.elastic.co/t/need-suggestion-how-to-boost-specific-documents-for-a-given-search-term/23441/2 "2015-04-30T05:57:56Z")

</div>

Any one has good suggestion?

On Tuesday, April 28, 2015 at 11:01:40 PM UTC+8, Xudong You wrote:

> Hi ES experts,
> 
> I need your help on index design for a real scenario. It might be a long  
> question, let me try explain it as concise as possible.
> 
> We are building a search engine to provide site search for our customers,  
> the document in index could be something like this:
> 
> { "Path":"[http://www.foo.com/doc/abc/1](http://www.foo.com/doc/abc/1)", "Title":"Title 1",  
> "Description":"The description of doc 1", ... }  
> { "Path":"[http://www.foo.com/doc/abc/2](http://www.foo.com/doc/abc/2)", "Title":"Title 2",  
> "Description":"The description of doc 2", ... }  
> { "Path":"[http://www.foo.com/doc/abc/3](http://www.foo.com/doc/abc/3)", "Title":"Title 3",  
> "Description":"The description of doc 3", ... }  
> ...
> 
> For each query, the returned hit documents are by default sorted by  
> relevance, but our customer also wants to _boost some specific documents  
> for some keywords,_  
> They will give us the following like boosting configuration XML:
> 
> http://www.foo.com/doc/abc/1 http://www.foo.com/doc/abc/2 http://www.foo.com/doc/abc/1 http://www.foo.com/doc/abc/3 http://www.foo.com/doc/abc/2 http://www.foo.com/doc/abc/1
> 
> That mean, if user search “keyword1", the top 1 hit document should be the  
> document whose Path field value is "[http://www.foo.com/doc/abc/1](http://www.foo.com/doc/abc/1)",  
> regardless the relevance score of that document. Similarly, if search  
> "keyword3", the top 3 hit documents should be "  
> [http://www.foo.com/doc/abc/3](http://www.foo.com/doc/abc/3)", "[http://www.foo.com/doc/abc/2](http://www.foo.com/doc/abc/2)" and "  
> [http://www.foo.com/doc/abc/1](http://www.foo.com/doc/abc/1)" respectively.
> 
> To satisfy this special requirement, my design is, firstly invert the  
> original boosting XML to following format:  
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
>   
> \<keyword value="keyword3" rank=9900" /\>
> 
> Then add a nested field "Boost", which contains a list of keyword/rank  
> field, to the document as following example:  
> {  
> "Boost": [  
> { "keyword":"keyword1", "rank": 10000},  
> { "keyword":"keyword2", "rank": 9900},  
> { "keyword":"keyword3", "rank": 9800}  
> ]  
> "Path":"[http://www.foo.com/doc/abc/1](http://www.foo.com/doc/abc/1)",  
> "Title":"Title 1",  
> "Description":"The description of doc 1",  
> ...  
> }
> 
> {  
> "Boost": [  
> { "keyword":"keyword2", "rank": 10000},  
> { "keyword":"keyword3", "rank": 9900}  
> ]  
> "Path":"[http://www.foo.com/doc/abc/2](http://www.foo.com/doc/abc/2)",  
> "Title":"Title 2",  
> "Description":"The description of doc 2",  
> ...  
> }
> 
> {  
> "Boost": [  
> { "keyword":"keyword3", "rank": 10000}  
> ]  
> "Path":"[http://www.foo.com/doc/abc/3](http://www.foo.com/doc/abc/3)",  
> "Title":"Title 3",  
> "Description":"The description of doc 3",  
> ...  
> }
> 
> Then in query time, use nested query to get the rank value of each matched  
> document for a given search keyword, and use the score script to adjust the  
> relevance score by the rank value. Since the rank value from boosting XML  
> is much larger than normal relevance score ( generally less than 5), the  
> adjusted score of the documents which configured in boosting XML for given  
> keyword should be top scores.
> 
> Does this design work well? Any suggestions to better design?
> 
> Thanks in advance!

--  
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/22af3d13-4d44-4550-9396-96d2974634ec%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/22af3d13-4d44-4550-9396-96d2974634ec%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:16am UTC](https://discuss.elastic.co/t/need-suggestion-how-to-boost-specific-documents-for-a-given-search-term/23441/3 "2017-07-06T00:16:50Z")

</div>


