ElasticSearch:查询多个字段

时间:2018-06-05 08:49:18

标签: php laravel elasticsearch

我是ElasticSearch的新手,我正在尝试查询嵌套文档的多个字段。它实际上只有在完全匹配时才会成功。

return Record::search()
            ->multiMatch([
                'original_name',
                'some_id',
                'contributors.name',
                'customNames.custom_name',
            ], ' * '.$searchTerm.' * ', ['fuzziness' => 'AUTO'])
            ->size(500)->get()->hits();

有什么想法吗?

SQL等价物是:

SELECT * FROM WHERE records LIKE '%'.$seachTerm.'%'(加上一些额外的联接)

1 个答案:

答案 0 :(得分:0)

 $query = [
            'multi_match' => [
                'query' => $searchTerm,
               'fields' => [
                    'original_name',
                    'some_id'
                ]
             ],
          ];

$records = Record::searchByQuery($query, '', '', $count, $offset, [
                'id' => ['order' => 'desc']
            ]);