Boosting at query time based on property value


(Yannick Smits) #1

Say I have this kind of records indexed in ES:

{
"book" {
"_id": 1234,
"author" : 100147,
"categories" : [3, 5, 7, 11],
"content" : "some text "
}
}

Say my user has defined a preference that it is more interested in
certain authors than others, so for instance would like to see books
from author 100147, 100234 and 100602 higher up in the search results
than other books. How can you now apply this boost at query time?
(same goes for categories btw).


(Shay Banon) #2

You can use a custom_score query, pass those values as params to the script, and boost based on that. http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html
On Thursday, May 12, 2011 at 1:20 AM, Yannick Smits wrote:

Say I have this kind of records indexed in ES:

{
"book" {
"_id": 1234,
"author" : 100147,
"categories" : [3, 5, 7, 11],
"content" : "some text "
}
}

Say my user has defined a preference that it is more interested in
certain authors than others, so for instance would like to see books
from author 100147, 100234 and 100602 higher up in the search results
than other books. How can you now apply this boost at query time?
(same goes for categories btw).


(Yannick Smits-2) #3

Thanks, I’ve meditated a week on your answer but can’t seem to grasp how that would work.

Should I use the script property to write some code and do some if statements? Like

“script”: “(doc['author'].value == 100147) ? 2 : 1”

Will this work or is there a more efficient way I’m not seeing?

Thanks,

Yannick “newbie”

From: Shay Banon [mailto:shay.banon@elasticsearch.com]
Sent: donderdag 12 mei 2011 11:01
To: users@elasticsearch.com
Subject: Re: boosting at query time based on property value

You can use a custom_score query, pass those values as params to the script, and boost based on that. http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html

On Thursday, May 12, 2011 at 1:20 AM, Yannick Smits wrote:

Say I have this kind of records indexed in ES:

{
"book" {
"_id": 1234,
"author" : 100147,
"categories" : [3, 5, 7, 11],
"content" : "some text "
}
}

Say my user has defined a preference that it is more interested in
certain authors than others, so for instance would like to see books
from author 100147, 100234 and 100602 higher up in the search results
than other books. How can you now apply this boost at query time?
(same goes for categories btw).


(Enrique Medina Montenegro) #4

Yannick,

I had a similar requirement which I solved using this code (Java), just in
case it can inspire yours. It consisted of discriminating the results
belonging to a special category (sorry about the spanish field names):

        queryCustom = customScoreQuery(querystring).script("if

(doc['categorias2'].multiValued) {foreach(cat:
doc['categorias2'].values){if(cat=='Libros'){return _score/1.5;}}return
_score;}else if(doc['categorias2'].stringValue=='Libros'){return
_score/2;}else{return _score;}");

On Thu, May 19, 2011 at 4:41 PM, Yannick Smits mailinglists@goyaweb.nlwrote:

Thanks, I’ve meditated a week on your answer but can’t seem to grasp how
that would work.

Should I use the script property to write some code and do some if
statements? Like

“script”: “(doc['author'].value == 100147) ? 2 : 1”

Will this work or is there a more efficient way I’m not seeing?

Thanks,

Yannick “newbie”

From: Shay Banon [mailto:shay.banon@elasticsearch.com]
Sent: donderdag 12 mei 2011 11:01
To: users@elasticsearch.com
Subject: Re: boosting at query time based on property value

You can use a custom_score query, pass those values as params to the
script, and boost based on that.
http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html

On Thursday, May 12, 2011 at 1:20 AM, Yannick Smits wrote:

Say I have this kind of records indexed in ES:

{
"book" {
"_id": 1234,
"author" : 100147,
"categories" : [3, 5, 7, 11],
"content" : "some text "
}
}

Say my user has defined a preference that it is more interested in
certain authors than others, so for instance would like to see books
from author 100147, 100234 and 100602 higher up in the search results
than other books. How can you now apply this boost at query time?
(same goes for categories btw).


(Karussell) #5

A lucene query works for this:

{ "query":{
"query_string" : {
"default_field" : "author",
"query" : "* OR author:ab^1 OR author:xy^10"
}
}}

Will this work or is there a more efficient way I’m not seeing?

using native script should be also a bit more efficient


(Yannick Smits-2) #6

Great! Could you explain to me the terms "lucene query" and "native script"?

Thanks,
Yannick

-----Original Message-----
From: Karussell [mailto:tableyourtime@googlemail.com]
Sent: vrijdag 20 mei 2011 21:58
To: users
Subject: Re: boosting at query time based on property value

A lucene query works for this:

{ "query":{
"query_string" : {
"default_field" : "author",
"query" : "* OR author:ab^1 OR author:xy^10"
}
}}

Will this work or is there a more efficient way I'm not seeing?

using native script should be also a bit more efficient


(Karussell) #7

With lucene query I mean that a 'standard' lucene query is used:

http://lucene.apache.org/java/3_1_0/queryparsersyntax.html

Native script was introduced lately in ES. You can write scripts with
java (but have all the drawbacks of it):

http://www.elasticsearch.org/guide/reference/modules/scripting.html

On May 20, 10:20 pm, Yannick Smits mailingli...@goyaweb.nl wrote:

Great! Could you explain to me the terms "lucene query" and "native script"?

Thanks,
Yannick

-----Original Message-----
From: Karussell [mailto:tableyourt...@googlemail.com]
Sent: vrijdag 20 mei 2011 21:58
To: users
Subject: Re: boosting at query time based on property value

A lucene query works for this:

{ "query":{
"query_string" : {
"default_field" : "author",
"query" : "* OR author:ab^1 OR author:xy^10"
}
}}

Will this work or is there a more efficient way I'm not seeing?

using native script should be also a bit more efficient


(system) #8