基于布尔字段值提升Elasticsearch结果 [英] Boosting an elasticsearch result based on a boolean field value

查看:114
本文介绍了基于布尔字段值提升Elasticsearch结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当布尔"字段类型为TRUE时,在寻找正确的方法来增强结果时,我会遇到很多静态"问题.大多数结果都在谈论布尔搜索.

I'm getting a lot of "static" when searching for the correct way to boost a result when a "Boolean" field type is TRUE, most results are talking about boolean searches.

N.B.我们正在使用php elastica库,但是如果您只能提供很好的json,我可以从中进行管理.

N.B. We're using the php elastica library but if you can only provide json that's fine, I can manage from that.

我有一个包含5个字段的索引,我们在其中建立了一些内置的Boosting,如您在此处看到的那样:

I have an index with 5 fields where we have some built in boosting going on as you can see here:

array(
    'article_id' => array('type' => 'string', 'include_in_all' => FALSE),
    'subject' => array('type' => 'string', 'include_in_all' => TRUE, 'boost' => 8),
    'summary' => array('type' => 'string', 'include_in_all' => TRUE, 'boost' => 5),
    'content' => array('type' => 'string', 'include_in_all' => TRUE, 'boost' => 3),
    'media'  => array('type' => 'boolean', 'include_in_all' => FALSE),
    'pub_date'  => array('type' => 'date', 'include_in_all' => FALSE)
)

我还通过使用\Elastica\Query\Bool()查询对象上的addShould()方法,通过基于年龄的pub_date字段,成功地在各个级​​别上提高了结果.

I'm also successfully boosting the results at a variety of levels via the pub_date field based on age using the addShould() method on a \Elastica\Query\Bool() query object.

我现在想做的是在media为TRUE的情况下进一步提高结果.

What I would like to do now is boost results further where media is TRUE.

有人可以告诉我如何为media字段添加适当的增强吗?

Can someone tell me how to add the appropriate boost for just the media field?

推荐答案

有多种提高结果的方法,请查看

There are different ways to boost your results, have a look at this question to know more. Your usecase seems easy, you could do it at index time but I would rather do it at query time, just adding a should clause to your bool query and giving a proper boost to it if needed:

{
    "bool" : {
        "must" : {
            ...
        },
        "should" : [
            {
                .....
            },
            {
                "term" : { "media" : "TRUE" }
            }
        ],
    }
}

new子句是可选的,但是它使匹配文档的分数更高.如有必要,可以为其添加特定的增强,其值主要取决于其他子句.

The new clause would be optional, but it makes the score of the matching documents higher. If necessary you can add a specific boost to it, its value mainly depends on the other clauses.

这篇关于基于布尔字段值提升Elasticsearch结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆