Skip to content

Latest commit

 

History

History
79 lines (60 loc) · 1.94 KB

joining-queries.md

File metadata and controls

79 lines (60 loc) · 1.94 KB

Joining Queries

Nested

Use nestedSearch to search in nested fields:

$searchResult = Book::nestedSearch()
    ->path('author')
    ->query(['match' => ['author.name' => 'Steven']])
    ->execute();

Available methods provided by NestedQueryBuilder:

ignoreUnmapped

You can use ignoreUnmapped to query multiple indices that may not contain the field path:

$searchResult = Book::nestedSearch()
    ->path('author')
    ->query(['match' => ['author.name' => 'Steven']])
    ->ignoreUnmapped(true)
    ->execute();

path

Use path to set a path to the nested field you wish to search in:

$searchResult = Book::nestedSearch()
    ->path('author')
    ->query(['match' => ['author.name' => 'Steven']])
    ->execute();

query

query defines a raw query you wish to run on the nested field:

// option 1: use query type and body
$searchResult = Book::nestedSearch()
    ->path('author')
    ->query('match', ['author.name' => 'Steven'])
    ->execute();

// option 2: use an array
$searchResult = Book::nestedSearch()
    ->path('author')
    ->query(['match' => ['author.name' => 'Steven']])
    ->execute();

// option 3: use a query builder
$searchResult = Book::nestedSearch()
    ->path('author')
    ->query((new MatchQueryBuilder())->field('author.name')->query('Steven'))
    ->execute();

scoreMode

scoreMode is used to set a scoring mode:

$searchResult = Book::nestedSearch()
    ->path('author')
    ->query(['match' => ['author.name' => 'Steven']])
    ->scoreMode('avg')
    ->execute();