This should do:
// Create a "global" query $query = new Elastica_Query; // Create the term query $term = new Elastica_Query_Term; $term->setTerm('click', 'true'); // Add term query to "global" query $query->setQuery($term); // Create the facet $facet = new Elastica_Facet_Terms('matches'); $facet->setField('pubid') ->setAllTerms(true) ->setSize(200); // Add facet to "global" query $query->addFacet($facet); // Output query echo json_encode($query->toArray());
To complete the request, you need to connect to ES servers
// Connect to your ES servers $client = new Elastica_Client(array( 'servers' => array( array('host' => 'localhost', 'port' => 9200), array('host' => 'localhost', 'port' => 9201), array('host' => 'localhost', 'port' => 9202), array('host' => 'localhost', 'port' => 9203), array('host' => 'localhost', 'port' => 9204), ), ));
And indicate which index and type you want to query for the query
// Get index $index = $client->getIndex('myindex'); $type = $index->getType('typename');
Now you can run your request
$type->search($query);
Edit : If you use the environment with names and the current version of Elastica, change all the lines in which new objects are created accordingly
$query = new \Elastica\Query; $facet = new \Elastica\Facet\Terms
etc.
source share