Skip to content

Latest commit

 

History

History
86 lines (61 loc) · 2.01 KB

joining-queries.md

File metadata and controls

86 lines (61 loc) · 2.01 KB

Joining Queries

Nested

You can use ElasticScoutDriverPlus\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();

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();