php如何做查询,php – 如何使用Elastica进行查询
這應該做:
// 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
等等
總結
以上是生活随笔為你收集整理的php如何做查询,php – 如何使用Elastica进行查询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab如何仿真斜坡信号,单斜坡AD
- 下一篇: UDT简介