thitami
thitami

Reputation: 838

ElasticSearch: Query on multiple fields

I am new to ElasticSearch and I am trying to query on multiple fields of a a nested document. It actually succeeds only when there is an exact match.

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

Any ideas?

SQL equivalent would be:

SELECT * FROM WHERE records LIKE '%'.$seachTerm.'%' (plus some extra joins)

Upvotes: 1

Views: 393

Answers (1)

Sara Vaseei
Sara Vaseei

Reputation: 833

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

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

Upvotes: 1

Related Questions