7. Multi Match

The multi_match query builds on the match query to allow multi-field queries:

 1<?php
 2
 3$search = $elastic->multiMatch()
 4                ->index('my-index')
 5                ->text('Şêro')
 6                ->fields(['name^3'])
 7                ->search();
 8
 9// If you want to set limit :
10$search = $elastic->multiMatch()
11                ->index('my-index')
12                ->size(10) // returns max 10 data
13                ->text('Şêro')
14                ->fields(['name^3'])
15                ->search();
16
17//  add fuzziness :
18$search = $elastic->multiMatch()
19                ->index('my-index')
20                ->size(10)
21                ->fuzziness(1) // Ideal value is 1 and 2
22                ->text('Şêro')
23                ->fields(['name^3'])
24                ->search();
25
26// Merge with sort query :
27$search = $elastic->multiMatch()
28                ->index('my-index')
29                ->size(10)
30                ->fuzziness(1)
31                ->text('Şêro')
32                ->fields(['name^3'])
33                ->mergeWith('elastic.sort', function(){
34                        return $this
35                                ->field('age')
36                                ->order('desc')
37                                ->getMap();
38                    })
39                ->search();
40
41// Merge with aggregations
42
43$search = $elastic->multiMatch()
44                ->index('my-index')
45                ->text('Şêro')
46                ->fuzziness(1)
47                ->fields(['name^3'])
48                ->mergeWith('elastic.aggs', function(){
49                  return $this
50                            ->name('my-aggs')
51                            ->terms([
52                                    'field' => 'age'
53                            ])
54                            ->subAggs(function(){
55                                return $this
56                                    ->name('sub-aggs')
57                                    ->scope([
58                                        'avg' => [
59                                            'field' => 'age'
60                                        ]
61                                    ])
62                                    ->getMap();
63                            })
64                            ->getMap();
65                })
66                ->search();
67
68// Merge with highlight query :
69$search = $elastic->multiMatch()
70                ->index('my-index')
71                ->size(10)
72                ->fuzziness(1)
73                ->text('Şêro')
74                ->fields(['name^3'])
75                ->mergeWith('elastic.sort', function(){
76                        return $this
77                                ->field('age')
78                                ->order('desc')
79                                ->getMap();
80                })
81                ->mergeWith('elastic.highlight', function(){
82                            return $this
83                                ->content('name', '<div>', '</div>')
84                                ->getMap();
85                })
86                ->search();
87
88// Other useful functions
89$search = $elastic->multiMatch()
90            ->index('my-index')
91            ->size(10)
92            ->fuzziness(1)
93            ->text('Şêro')
94            ->fields(['name^3'])
95            ->analyzer('standard')
96            ->tieBreaker(0.3)
97            ->operator('and')
98            ->type('most_fields')
99            ->search();