对筛选查询的结果进行排序

时间:2013-02-12 20:59:35

标签: php elasticsearch elastica

由于有大量的过滤条件(1000s中的权限系统),我必须使用Elastic_Query_Filtered这很好,我甚至可以使用

设置分页限制
$elasticaType->search($elasticaQueryString, $options);

在我介绍排序选项之前,这一切都很有效。这是我到目前为止所做的:

$options = array('from'=>$from, 'size'=>$to, 'sort'=>array("description" => array("order" => "asc")));
$elasticaResultSet = $elasticaType->search($elasticaQueryString, $options);

我做的事情是愚蠢的还是排序还不支持。有替代方案吗?使用bool过滤器会使事情发生max_clause_count

1 个答案:

答案 0 :(得分:0)

我用它来搜索单个查询字符串,带有限制和排序

$client = new Elastica_Client(array('host' => '192.168.0.27','port' => '9200'));

$elasticaQueryString =new Elastica_Query_QueryString();
$elasticaQueryString->setDefaultOperator('AND');
$elasticaQueryString->setQuery('100009'); // set value for where condition
$elasticaQueryString->setFields(array('increment_id','entity_id','billing_name'));  // set where fields

$elasticaQuery = new Elastica_Query();
$elasticaQuery->setQuery($elasticaQueryString);  // set query string
$elasticaQuery->setFields(array('increment_id','entity_id','billing_name','created_at'));   // set output fields

$elasticaQuery->setFrom(0); //set from point   
$elasticaQuery->setLimit(20);  //limit the record   
$sort = array("entity_id" => array("order" => "asc"));  //order by clause

$elasticaQuery->setSort($sort);  //set Sorting

echo "<br />".json_encode($elasticaQuery->toArray())."<br />";  //print the query

$search = new Elastica_Search($client); // Create the search object and inject the client
$resultSet = $search->addIndex('sales')->addType('order')->search($elasticaQuery);  // Configure and execute the search

echo "<br /><strong>Total Results Found : ".$totalResults= $resultSet->getTotalHits()."</strong><br />";            //get total result found

$data=$resultSet->getResults(); //extract the result

$result=array();

foreach ($data as $data1) 
{
  $result[]=$data1->getData();
}

print_r($result);
相关问题