Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Query

Objective query builder represents all available Elasticsearch queries.

To form a query you have to create Search object. See below an example of match all query usage.

$search = new Search();
$matchAllQuery = new MatchAllQuery();
$search->addQuery($matchAllQuery);
$queryArray = $search->toArray();
//$queryArray content
'query' =>
    [
      'match_all' => \stdClass(),
    ]

So now you can easily pass it to the elasticsearch-php client:

//from elasticsearch/elasticsearch package
$client = new Elasticsearch\Client();

$searchParams = [
  'index' => 'people',
  'type' => 'person',
  'body' => $queryArray
];

$docs = $client->search($searchParams);

This example works with elasticsearch/elasticsearch ~1.0 version.

Queries: