Skip to content

Latest commit

 

History

History
100 lines (71 loc) · 2.5 KB

joining-queries.md

File metadata and controls

100 lines (71 loc) · 2.5 KB

Joining Queries

Nested

You can use Elastic\ScoutDriverPlus\Support\Query::nested() to build a nested query:

$query = Query::nested()
    ->path('author')
    ->query(Query::match()->field('author.name')->field('Steven'));

$searchResult = Book::searchQuery($query)->execute();

Available methods:

ignoreUnmapped

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

$query = Query::nested()
    ->path('author')
    ->query(Query::match()->field('author.name')->field('Steven'))
    ->ignoreUnmapped(true);

$searchResult = Book::searchQuery($query)->execute();

innerHits

innerHits support the following options: from, size, sort, name and some per document features:

$query = Query::nested()
    ->path('author')
    ->query(Query::match()->field('author.name')->field('Steven'))
    ->innerHits(['name' => 'authors']);

$searchResult = Book::searchQuery($query)->execute();

path

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

$query = Query::nested()
    ->path('author')
    ->query(Query::match()->field('author.name')->field('Steven'));

$searchResult = Book::searchQuery($query)->execute();

query

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

// you can make a query using builder
$query = Query::nested()
    ->path('author')
    ->query(Query::match()->field('author.name')->field('Steven'));

// or you can define a raw query
$query = [
    'nested' => [
        'path' => 'author',
        'query' => [
            'match' => [
               'author.name' => 'Steven'
            ]
        ]
    ]
];

$searchResult = Book::searchQuery($query)->execute();

scoreMode

scoreMode is used to set a scoring mode:

$query = Query::nested()
    ->path('author')
    ->query(Query::match()->field('author.name')->field('Steven'))
    ->scoreMode('avg');

$searchResult = Book::searchQuery($query)->execute();