これは行う必要があります:
// 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());
クエリを実行するには、ESサーバーに接続する必要があります
// 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),
),
));
そして、クエリを実行するインデックスとタイプを指定します
// Get index
$index = $client->getIndex('myindex');
$type = $index->getType('typename');
これで、クエリを実行できます
$type->search($query);
編集:名前空間環境とElasticaの現在のバージョンを使用している場合は、それに応じて新しいオブジェクトが作成されるすべての行を次のように変更します。
$query = new \Elastica\Query;
$facet = new \Elastica\Facet\Terms
等々