Skip to content
Snippets Groups Projects
Code owners
index.md 1.61 KiB

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: