-4

Following this question and it's answers, I'm trying to do the same but with the PHP Elastica and I wasn't successful doing it.

I am trying to give my new \Elastica\Query\Terms an array and I can't find the right way to do so.

I've tried doing it this way :

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

Where $array_pids is an array containing multiple ids :

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

The term aggregation is expecting a $key => $value and the $value can't be an array, if it's not a number he gives me an error.

[terms] query does not support [null]]

The question is, how to correctly pass to the terms aggregation an array instead of a number to simulate an SQL : IN ?

Alexandre Elshobokshy
  • 10,720
  • 6
  • 27
  • 57

2 Answers2

1

Try this instead:

$terms = new Elastica\Query\Terms();       
$terms->setTerms($grp_field_p, $array_pids);  
Val
  • 207,596
  • 13
  • 358
  • 360
  • I do get a [`TooManyClauses[maxClauseCount is set to 1024]`](https://stackoverflow.com/questions/40275514/elasticsearch-set-max-clause-count) error but I suppose that's another problem, thanks! – Alexandre Elshobokshy Oct 10 '18 at 10:01
1

Based on its source code :

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

it should work like this:

new Elastica\Query\Terms($grp_field_p, $array_pids); 
Alexandre Elshobokshy
  • 10,720
  • 6
  • 27
  • 57
deerawan
  • 8,002
  • 5
  • 42
  • 51