Unexpected Response when adding objects
ideiasfrescas opened this issue · 5 comments
- Algolia Client Version: 3.0 ( PHP )
- Language Version: PHP 7.3
Description
I'm getting a large response object after I try to insert a new object with autoobject id.
Steps To Reproduce
I'm using the following code:
$algarveClient = Algolia\AlgoliaSearch\SearchClient::create(
ALGALIA_APPID,
ALGALIA_AKEY
);
$INDEX = $algarveClient->initIndex(ALGALIA_INDICE);
$OUT = $INDEX->saveObject([
'titulo' => $titulo["pt"],
'texto' => "teste",
'link' => $link_pt
],
[
'autoGenerateObjectIDIfNotExist' => true
]);
when var_dumping $OUT i get this:
object(Algolia\AlgoliaSearch\Response\BatchIndexingResponse)#30 (3) {
["index":"Algolia\AlgoliaSearch\Response\BatchIndexingResponse":private]=>
object(Algolia\AlgoliaSearch\SearchIndex)#29 (3) {
["indexName":"Algolia\AlgoliaSearch\SearchIndex":private]=>
string(15) "arrabida_parque"
["api":protected]=>
object(Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper)#23 (6) {
["http":"Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper":private]=>
object(Algolia\AlgoliaSearch\Http\CurlHttpClient)#24 (2) {
["curlMHandle":"Algolia\AlgoliaSearch\Http\CurlHttpClient":private]=>
resource(9) of type (curl_multi)
["curlOptions":"Algolia\AlgoliaSearch\Http\CurlHttpClient":private]=>
array(0) {
}
}
["config":"Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper":private]=>
object(Algolia\AlgoliaSearch\Config\SearchConfig)#11 (5) {
["defaultWaitTaskTimeBeforeRetry":"Algolia\AlgoliaSearch\Config\SearchConfig":private]=>
int(100000)
["config":protected]=>
array(10) {
["appId"]=>
string(10) "NSDPL38HQG"
["apiKey"]=>
string(32) "API_KEY"
["hosts"]=>
NULL
["readTimeout"]=>
int(5)
["writeTimeout"]=>
int(30)
["connectTimeout"]=>
int(2)
["waitTaskTimeBeforeRetry"]=>
int(100000)
["defaultHeaders"]=>
array(0) {
}
["defaultForwardToReplicas"]=>
NULL
["batchSize"]=>
int(1000)
}
["defaultReadTimeout":protected]=>
int(5)
["defaultWriteTimeout":protected]=>
int(30)
["defaultConnectTimeout":protected]=>
int(2)
}
["clusterHosts":"Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper":private]=>
object(Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts)#12 (5) {
["read":"Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts":private]=>
object(Algolia\AlgoliaSearch\RetryStrategy\HostCollection)#17 (1) {
["hosts":"Algolia\AlgoliaSearch\RetryStrategy\HostCollection":private]=>
array(4) {
[0]=>
object(Algolia\AlgoliaSearch\RetryStrategy\Host)#16 (4) {
["url":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
string(26) "NSDPL38HQG-dsn.algolia.net"
["priority":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
int(10)
["up":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
bool(true)
["lastCheck":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
NULL
}
[1]=>
object(Algolia\AlgoliaSearch\RetryStrategy\Host)#15 (4) {
["url":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
string(27) "NSDPL38HQG-3.algolianet.com"
["priority":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
int(0)
["up":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
bool(true)
["lastCheck":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
NULL
}
[2]=>
object(Algolia\AlgoliaSearch\RetryStrategy\Host)#14 (4) {
["url":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
string(27) "NSDPL38HQG-2.algolianet.com"
["priority":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
int(0)
["up":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
bool(true)
["lastCheck":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
NULL
}
[3]=>
object(Algolia\AlgoliaSearch\RetryStrategy\Host)#13 (4) {
["url":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
string(27) "NSDPL38HQG-1.algolianet.com"
["priority":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
int(0)
["up":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
bool(true)
["lastCheck":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
NULL
}
}
}
["write":"Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts":private]=>
object(Algolia\AlgoliaSearch\RetryStrategy\HostCollection)#22 (1) {
["hosts":"Algolia\AlgoliaSearch\RetryStrategy\HostCollection":private]=>
array(4) {
[0]=>
object(Algolia\AlgoliaSearch\RetryStrategy\Host)#21 (4) {
["url":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
string(22) "NSDPL38HQG.algolia.net"
["priority":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
int(10)
["up":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
bool(true)
["lastCheck":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
NULL
}
[1]=>
object(Algolia\AlgoliaSearch\RetryStrategy\Host)#18 (4) {
["url":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
string(27) "NSDPL38HQG-1.algolianet.com"
["priority":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
int(0)
["up":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
bool(true)
["lastCheck":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
NULL
}
[2]=>
object(Algolia\AlgoliaSearch\RetryStrategy\Host)#20 (4) {
["url":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
string(27) "NSDPL38HQG-3.algolianet.com"
["priority":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
int(0)
["up":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
bool(true)
["lastCheck":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
NULL
}
[3]=>
object(Algolia\AlgoliaSearch\RetryStrategy\Host)#19 (4) {
["url":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
string(27) "NSDPL38HQG-2.algolianet.com"
["priority":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
int(0)
["up":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
bool(true)
["lastCheck":"Algolia\AlgoliaSearch\RetryStrategy\Host":private]=>
NULL
}
}
}
["cacheKey":"Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts":private]=>
string(58) "Algolia\AlgoliaSearch\SearchClient-clusterHosts-NSDPL38HQG"
["lastReadHash":"Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts":private]=>
NULL
["lastWriteHash":"Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts":private]=>
NULL
}
["requestOptionsFactory":"Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper":private]=>
object(Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory)#25 (3) {
["config":"Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory":private]=>
object(Algolia\AlgoliaSearch\Config\SearchConfig)#11 (5) {
["defaultWaitTaskTimeBeforeRetry":"Algolia\AlgoliaSearch\Config\SearchConfig":private]=>
int(100000)
["config":protected]=>
array(10) {
["appId"]=>
string(10) "NSDPL38HQG"
["apiKey"]=>
string(32) "API_KEY"
["hosts"]=>
NULL
["readTimeout"]=>
int(5)
["writeTimeout"]=>
int(30)
["connectTimeout"]=>
int(2)
["waitTaskTimeBeforeRetry"]=>
int(100000)
["defaultHeaders"]=>
array(0) {
}
["defaultForwardToReplicas"]=>
NULL
["batchSize"]=>
int(1000)
}
["defaultReadTimeout":protected]=>
int(5)
["defaultWriteTimeout":protected]=>
int(30)
["defaultConnectTimeout":protected]=>
int(2)
}
["validQueryParameters":"Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory":private]=>
array(4) {
[0]=>
string(17) "forwardToReplicas"
[1]=>
string(23) "replaceExistingSynonyms"
[2]=>
string(18) "clearExistingRules"
[3]=>
string(10) "getVersion"
}
["validHeaders":"Algolia\AlgoliaSearch\RequestOptions\RequestOptionsFactory":private]=>
array(3) {
[0]=>
string(12) "Content-type"
[1]=>
string(10) "User-Agent"
[2]=>
string(17) "createIfNotExists"
}
}
["logger":"Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper":private]=>
object(Algolia\AlgoliaSearch\Log\DebugLogger)#26 (0) {
}
["jsonOptions":"Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper":private]=>
int(256)
}
["config":protected]=>
object(Algolia\AlgoliaSearch\Config\SearchConfig)#11 (5) {
["defaultWaitTaskTimeBeforeRetry":"Algolia\AlgoliaSearch\Config\SearchConfig":private]=>
int(100000)
["config":protected]=>
array(10) {
["appId"]=>
string(10) "NSDPL38HQG"
["apiKey"]=>
string(32) "API_KEY"
["hosts"]=>
NULL
["readTimeout"]=>
int(5)
["writeTimeout"]=>
int(30)
["connectTimeout"]=>
int(2)
["waitTaskTimeBeforeRetry"]=>
int(100000)
["defaultHeaders"]=>
array(0) {
}
Is this somekind of limit imposed by the Free Plan?
Is the object itself large, or is it in fact just referencing other objects through properties, that are themselves doing the same? BatchIndexingResponse -> SearchIndex -> ApiWrapper, etc.
I'm not sure what you mean by large. I have made updates to another object in the same index which has about 3700 chars of text and Algolia is able to update with Partial Update, with no issues.
In an "Add new object" scenario I have a resulting json ( see below an example call to saveObject ) roughly the same length in chars and the response from algolia comes like that.
I can describe my workflow.
I'm working in a custom made CMS, that is developed to support multiple languages, Each language, has it's own algolia index, in order to provide search capability to the website for each language the user is on.
After I create a new record in my database, I start the algolia client and for each language, I choose the appropriate Algolia index ( I have only two indexes configured ) for that language and then I add the object accordinly
After I add the object, I should be getting the JSON reply with the new objectID. Then I would save it in my database so I can update or delete that object from Algolia at a later time.
An example call looks like this ( with production ready content ):
$OUT = $INDEX->saveObject([
'titulo' => "testing",
'texto' => "<p>As &aacute;guas da costa da Arr&aacute;bida-Espichel encontram-se protegidas pelo Parque Marinho Professor Luiz Saldanha,&nbsp;criado em 1998 com o principal objetivo de proteger e recuperar a biodiversidade deste mar especial. Para isso, o Parque promove a&ccedil;&otilde;es de conserva&ccedil;&atilde;o e gere as diversas atividades humanas que se praticam nestas &aacute;guas, de modo a compatibilizar objetivos de conserva&ccedil;&atilde;o com usos humanos sustent&aacute;veis.&nbsp;<\/p>\n<p>Toda a &aacute;rea do Parque Marinho faz parte do&nbsp;Parque Natural da Arr&aacute;bida, gerido pelo Instituto da Conserva&ccedil;&atilde;o da Natureza e das Florestas (ICNF), e est&aacute; integrada na rede Europeia de zonas de conserva&ccedil;&atilde;o &ndash; <a href="https:\/\/ec.europa.eu\/environment\/nature\/natura2000\/index_en.htm">Rede Natura 2000<\/a>. O sucesso do Parque Marinho beneficia da colabora&ccedil;&atilde;o das comunidades locais, as quais procuram adaptar as suas atividades ligadas ao mar (ex.: pesca, mergulho, passeios de barco) &agrave; capacidade de recupera&ccedil;&atilde;o e conserva&ccedil;&atilde;o dos ecossistemas marinhos. Simultaneamente, os cientistas apoiam o Parque avaliando a efic&aacute;cia das medidas de gest&atilde;o (ex.: estudos de monitoriza&ccedil;&atilde;o), aprofundando o conhecimento sobre o Parque Marinho, colocando em pr&aacute;tica a&ccedil;&otilde;es de conserva&ccedil;&atilde;o e promovendo o envolvimento das comunidades locais e visitantes.<\/p>",
'link' => 'https://arrabidaparquemarinho.ualg.pt'
],
[
'autoGenerateObjectIDIfNotExist' => true
]);
` ``
I'm not sure what you mean by large.
I mean exactly the same thing as you in your original message. What I was pointing out is the fact is that if you have an object that looks like this:
class Response
{
private $index;
private $interestingPropertyYouWouldLikeToSeeInVarDump;
}
and if $index
is an object that has itself properties that themselves are objects with many properties… you might never get to see $interestingPropertyYouWouldLikeToSeeInVarDump
in your var_dump
.
I think you should try var_dump($response->getBody());
if you want to see what you get back from Algolia the API, instead of what object graph you get from algoliasearch-client-php.
@greg0ire is right, you can indeed call the getBody
method on your response to get the JSON.
$algarveClient = Algolia\AlgoliaSearch\SearchClient::create(
ALGALIA_APPID,
ALGALIA_AKEY
);
$INDEX = $algarveClient->initIndex(ALGALIA_INDICE);
$OUT = $INDEX->saveObject([
'titulo' => $titulo["pt"],
'texto' => "teste",
'link' => $link_pt
],
[
'autoGenerateObjectIDIfNotExist' => true
]);
var_dump($OUT->getBody());
Also, @ideiasfrescas , I sent you an email, please have a look when you can.
@DevinCodes thank you for bringing us to that attention.
We will try out that getBody() and give feedback if we are still having trouble.