Negative boosts are not supported. The challenge in downranking is that
each boost value will contribute to the score and push docs higher, also
when using very small boost values or negative values. This is not what is
expected.

The trick for successful downranking is to reward all docs that do not
match the condition

{
    "bool": {
        "must_not": {
            "term": {
                "some_flag": true
            }
        },
        "boost": 0.00001
    }
}

which is equivalent to

{
    "bool": {
        "must": {
            "term": {
                "some_flag": false
            }
        },
        "boost": 0.00001
    }
}

given that some_flag exists in all docs.

This clause means: reward all docs that do not match the condition
some_flag=true and push them higher in the result set. In other words,
penalize all docs that match the condition some_flag=true.

Jörg



On Mon, Mar 2, 2015 at 7:03 PM, Joel Potischman <
[email protected]> wrote:

> I have a query template that currently returns results exactly as desired.
> I've been given a requirement to very slightly downrank results that have
> an optional boolean field set to True. The intent is to ensure that we
> return everything that matches the query, but if multiple records match,
> any with this flag set to true come up later in results. In case it's
> relevant, most records will not contain this flag. I came up with the
> following (simplified) version of my query which works great:
>
> {
>     "query": {
>         "bool": {
>             "should": [
>                 {
>                     "match": {
>                         "my_field": {
>                             "query": "{{q}}"
>                         }
>                     }
>                 },
>                 {
>                     "bool": {
>                         "must": {
>                             "term": {
>                                 "some_flag": true
>                             }
>                         },
>                         "boost": -0.00001
>                     }
>                 }
>             ]
>         }
>     }
> }
>
> A colleague said that we learned in our Elasticsearch training last year
> that we should avoid negative boosts, and I should rewrite the second
> clause as follows
>
> {
>     "bool": {
>         "must_not": {
>             "term": {
>                 "some_flag": false
>             }
>         },
>         "boost": 0.00001
>     }
> }
>
> I don't recall learning that, and this construction strikes me as less
> performant, as it must modify most records instead of just the minority
> that will have *some_flag=true*.
>
> Because we're both relatively new to Elasticsearch we'd very much
> appreciate someone with more experience to weigh in. I'm happy to change it
> if it's the right thing to do. I'm just not sure I believe it is, and if
> so, why.
>
> Thanks in advance.
>
> -joel
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/2113c100-7283-464e-b989-d58853d24a17%40googlegroups.com
> <https://groups.google.com/d/msgid/elasticsearch/2113c100-7283-464e-b989-d58853d24a17%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAKdsXoH0ohQM3e1Gh1pJFZKKe%2BvXfq7D63%3DgnS7PzZdhZG_-eQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to