当存在关系时,如何在Elasticsearch中查询?

时间:2015-12-16 03:26:38

标签: laravel elasticsearch laravel-5.1

我有两个型号:

  • 分类

每个帖子至少有一个类别,这个关系会显示一个包含帖子ID和类别ID的数据透视表。

我已经制作了代码来查询关键字,但我仍然无法想办法在搜索中包含该类别。

在我的帖子模型中:

use ElasticquentTrait;

protected $mappingProperties = array(
    'id' => [
        'type' => 'integer',
    ],
    'name' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
    'description' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
    'address' => [
        'type' => 'string',
        "analyzer" => "standard",
    ],
);

这是搜索查询的代码:

$search_results = BusinessListing::searchByQuery([
    'multi_match' => [
        'query' => $search_term,
        'fields' => [ "name^5", "description", "address"],
        'fuzziness' => "AUTO"
    ],
]);

我想到的一个解决方案就是用laravel过滤掉结果并删除带有不匹配类别的结果,但我不认为这是最佳解决方案。

我正在使用elasticquent/elasticquent库。

非常感谢帮助。非常感谢你!

0 个答案:

没有答案