Cannot add new index entries : Operations quota exceeded, change plan to get more Operations


I am currently setting up Algolia on my website (written in php) using the free trial version. My first command was to add entries to the database using the example provided in the tutorial within a searchEngine class:

class SearchEngine
{  private $_db; // Instance de PDO.
 private $_aPIKeySearchOnly;
 private $_aPIKeyAdmin;
 private $_aPIID; 
 private $_client;
 private $_indexProjet;
 private $_indexTag;
 private $_indexMedia;

 public function __construct($db)
  $pathroot = $_SERVER['DOCUMENT_ROOT'];
  $this->_client=new \AlgoliaSearch\Client($this->_aPIID, $this->_aPIKeyAdmin);
  $this->_indexProjet = $this->_client->initIndex('projet');
  $this->_indexTag = $this->_client->initIndex('tag');
  $this->_indexMedia = $this->_client->initIndex('media');

public function loadIndex(){

$records = [
  ['name' => 'Tom Cruise'],
  ['name' => 'Scarlett Johansson']
$status = $this->_indexProjet->addObjects($records);

And I got an error:

Warning: Invalid argument supplied for foreach() in D:\wamp64\www\soconline\htdocs\vendor\algolia\algoliasearch-client-php\src\AlgoliaSearch\Index.php on line 1276
Call Stack
#	Time	Memory	Function	Location
1	0.0020	452424	{main}( )	...\MAJProjet.php:0
2	1.1851	1548496	ProjetManager->add( )	...\MAJProjet.php:244
3	1.3471	2152600	SearchEngine->loadIndex( )	...\ProjetManager.php:80
4	1.3491	2156904	AlgoliaSearch\Index->addObjects( )	...\searchEngine.php:129
5	1.3491	2156984	AlgoliaSearch\Index->buildBatch( )	...\Index.php:167

array (size=2)
  0 => 
    array (size=1)
      'name' => string 'Tom Cruise' (length=10)
  1 => 
    array (size=1)
      'name' => string 'Scarlett Johansson' (length=18)

So i’m not sure what is going wrong, but i suppose that we cannot provide array to the addObjects function. How to circumvent this?


You shouldn’t be circumventing this, if you are adding more than 10,000 products on the free trial; that’s a hard-limit you can’t break. Try adding less products?

However, I too have been getting this error even though I have less than 10,000 products indexed. Very odd.

Though you could catch the error so it fails gracefully.


That’s how addObjects is supposed to be used.

Can you dump objects in the buildBatch method?


@NiceKiwi : I did not notice that the records have actualy been saved on Algolia server. So I can try catching the error and keeping it quiet but… well that is really dirty. I don’t like this no-solution but if I can’t have a better one…
@Julienbourdeau : I can’t find the buildBatch method your talking about on Algolia documentation… Do you have some more information? I tried sending objects with batch of 1000 elements but the problem is the same. May be it is related to wamp? Did you got some similar feedbacks?

This method is internal so it’s not documented. I wanted to get the var_dump in this method because it’s seems to be the root of the issue (according to your stack trace).

You can find it in vendor/algolia/algoliasearch-client-php/src/AlgoliaSearch/Index.php

I tried to reproduce the bug with a var_dump on $object as you suggested but then I have header sending error:
Warning: Cannot modify header information - headers already sent by (output started at D:\wamp64\www\soconline\htdocs\vendor\algolia\algoliasearch-client-php\src\AlgoliaSearch\Index.php:168) in D:\wamp64\www\soconline\htdocs\controler\projet\MAJProjet.php on line 287
obviouly because I try to redirect the user while I already send information via var_dump.
However I cannot reproduce the bug anymore (even without the debuging mode). I did not change anything in the code. However I did delete all my entries in Algolia database.
I can only assume that the bug is fixed (hopefully). May be a problem of connection whith algolia server, i don’t know…
I will reply to this post if I experience this issue again with a var_dump on $object.