Customize score when fields are missing


(Crwe-2) #1

Hello all,

I'd like to demote documents that are missing a specific field (either
"url" or "custom-url"), because documents with URLs are more relevant.
(Or, equivalently, promote documents that contain at least one of these
fields.)

How can this be achieved in ElasticSearch?


(Clinton Gormley) #2

On Thu, 2012-07-19 at 02:43 -0700, Crwe wrote:

Hello all,

I'd like to demote documents that are missing a specific field
(either "url" or "custom-url"), because documents with URLs are more
relevant.
(Or, equivalently, promote documents that contain at least one of
these fields.)

curl -XGET 'http://127.0.0.1:9200/_all/_search?pretty=1' -d '
{
"query" : {
"custom_filters_score" : {
"query" : {
"text" : {
"title" : "search keywords"
}
},
"filters" : [
{
"boost" : "2",
"filter" : {
"exists" : {
"field" : "url"
}
}
}
]
}
}
}
'


(Crwe-2) #3

Muchas gracias senor Gormley, exactly what I needed! I guess the "either
url or custom-url" part can be accomplished using an OR filter with two
"exists" parts.

On Thursday, July 19, 2012 11:56:17 AM UTC+2, Clinton Gormley wrote:

On Thu, 2012-07-19 at 02:43 -0700, Crwe wrote:

Hello all,

I'd like to demote documents that are missing a specific field
(either "url" or "custom-url"), because documents with URLs are more
relevant.
(Or, equivalently, promote documents that contain at least one of
these fields.)

curl -XGET 'http://127.0.0.1:9200/_all/_search?pretty=1' -d '
{
"query" : {
"custom_filters_score" : {
"query" : {
"text" : {
"title" : "search keywords"
}
},
"filters" : [
{
"boost" : "2",
"filter" : {
"exists" : {
"field" : "url"
}
}
}
]
}
}
}
'


(system) #4