Elastica:Elastica中的IN等效运算符

时间:2018-10-10 09:42:09

标签: elasticsearch elastica

this question and it's answers之后,我尝试使用PHP Elastica做同样的事情,但并没有成功。

我正在尝试给new \Elastica\Query\Terms一个数组,但找不到正确的方法。

我尝试过这种方式:

new \Elastica\Query\Terms(array($grp_field_p => array('value' => $array_pids)))

$array_pids是包含多个ID的数组:

array(
    1,
    2,
    3,
    ...
    23015
);

聚合一词期望$key => $value,而$value不能是数组,如果不是数字,他会给我一个错误。

  

[条款]查询不支持[null]]

问题是,如何正确地将集合(而不是数字)传递给术语聚合以模拟SQL : IN

2 个答案:

答案 0 :(得分:1)

尝试以下方法:

$terms = new Elastica\Query\Terms();       
$terms->setTerms($grp_field_p, $array_pids);  

答案 1 :(得分:1)

基于其source code

public function __construct($key = '', array $terms = [])
{
    $this->setTerms($key, $terms);
}

它应该像这样工作:

new Elastica\Query\Terms($grp_field_p, $array_pids); 
相关问题