基于布尔字段值提升弹性搜索结果

ouc*_*cil 1 php lucene elasticsearch elastica

当“布尔”字段类型为 TRUE 时,在搜索提高结果的正确方法时,我得到了很多“静态”,大多数结果都在谈论布尔搜索。

注意我们正在使用 php elastica 库,但是如果您只能提供 json 就好了,我可以从中进行管理。

我有一个包含 5 个字段的索引,我们在其中进行了一些内置提升,如您所见:

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)
)
Run Code Online (Sandbox Code Playgroud)

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

我现在想做的是在mediaTRUE 处进一步提高结果。

有人能告诉我如何为该media领域添加适当的提升吗?

jav*_*nna 5

有多种方法可以提高您的结果,请查看此问题以了解更多信息。你的用例看起来很简单,你可以在索引时做,但我宁愿在查询时做,只需在你的bool 查询中添加一个 should 子句,并在需要时给予适当的提升:

{
    "bool" : {
        "must" : {
            ...
        },
        "should" : [
            {
                .....
            },
            {
                "term" : { "media" : "TRUE" }
            }
        ],
    }
}
Run Code Online (Sandbox Code Playgroud)

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