Easiest way to boost field value?


(Tomasz Kloc) #1

hello,

what is the easiest way to boost field in TextQuery? lets say i have two
documents:

{'title': 'string1', description: ''}
{'title': 'string2', description: 'string1' }

and i want to find documents where title OR description contains
'string1', but matches in 'title' attribute should have higher score
than 'description'?

tk


(Shay Banon) #2

You can associate a boost value with a query:

{
"text" : {
"desc" : {
"query" : "text here",
"boost" : 5.0f
}
}
}

Another option is to wrap the query in a custom_boost_query (http://www.elasticsearch.org/guide/reference/query-dsl/custom-boost-factor-query.html) which simply multiplies the wrapped query by the custom boost factor.

On Monday, February 27, 2012 at 11:54 AM, Tomasz Kloc wrote:

hello,

what is the easiest way to boost field in TextQuery? lets say i have two
documents:

{'title': 'string1', description: ''}
{'title': 'string2', description: 'string1' }

and i want to find documents where title OR description contains
'string1', but matches in 'title' attribute should have higher score
than 'description'?

tk


(Tomasz Kloc) #3

Thanks Shay, I ended up with query like this:

{'query':
{ 'bool':
{ 'should':
[
{'text': {'title': {'query': 'my querystring', 'operator': 'and',
'boost': 5 } } },
{'text': {'description': { 'query': 'my querystring', 'operator':
'and', 'boost': 1 } } }
]
}
}
}

On 27.02.2012 14:12, Shay Banon wrote:

You can associate a boost value with a query:

{
"text" : {
"desc" : {
"query" : "text here",
"boost" : 5.0f
}
}
}

Another option is to wrap the query in a custom_boost_query
(http://www.elasticsearch.org/guide/reference/query-dsl/custom-boost-factor-query.html)
which simply multiplies the wrapped query by the custom boost factor.

On Monday, February 27, 2012 at 11:54 AM, Tomasz Kloc wrote:

hello,

what is the easiest way to boost field in TextQuery? lets say i have two
documents:

{'title': 'string1', description: ''}
{'title': 'string2', description: 'string1' }

and i want to find documents where title OR description contains
'string1', but matches in 'title' attribute should have higher score
than 'description'?

tk


(system) #4