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