How to specify Field weights

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

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' -d '
{
"query" : {
"dis_max" : {
"queries" : [
{
"text" : {
"title" : {
"boost" : 2,
"query" : "keywords"
}
}
},
{
"text" : {
"content" : "keywords"
}
}
]
}
}
}
'

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

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

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!