PHP Client Suggestion BadRequest400Exception

I'm using the PHP client.
I can search no problem.

My problem is getting suggestions.
Here is my code:

$json = '
POST /my_search_engine/_suggest
{
  "my_engine":{
    "text":"'.$keyword.'",
    "completion":{
      "field":"title_suggest"
    }
  }
}';

$params ['body'] = $json;
$response = $client->suggest ( $params );

Here is the stack trace:

<b>Fatal error</b>:  Uncaught exception 'Elasticsearch\Common\Exceptions\BadRequest400Exception' with message '{&quot;error&quot;:{&quot;root_cause&quot;:[{&quot;type&quot;:&quot;parse_exception&quot;,&quot;reason&quot;:&quot;Failed to derive xcontent&quot;}],&quot;type&quot;:&quot;parse_exception&quot;,&quot;reason&quot;:&quot;Failed to derive xcontent&quot;},&quot;status&quot;:400}' in /var/www/ats-site-lib/ats-site-thoracic/web/app/es_search/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:681
Stack trace:
#0 /var/www/ats-site-lib/ats-site-thoracic/web/app/es_search/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(659): Elasticsearch\Connections\Connection-&gt;tryDeserializeError(Array, 'Elasticsearch\C...')
#1 /var/www/ats-site-lib/ats-site-thoracic/web/app/es_search/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(579): Elasticsearch\Connections\Connection-&gt;tryDeserialize400Error(Array)
#2 /var/www/ats-site-lib/ats-site-thoracic/web/app/es_search/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(261): Elasticsearch in <b>/var/www/ats-site-lib/ats-site-thoracic/web/app/es_search/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php</b> on line <b>682</b><br />

Here is how a document's "title_suggest" completion field looks. I am storing an array of keywords. maybe this is the problem? :

"title_suggest": [
"Membership",
"Renewal"
]

Any help would be appreciated!

Here is the solution:

$json = '
{
  "thoracic":{
    "text":"'.$keyword.'",
    "completion":{
      "field":"title_suggest"
    }
  }
}';

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.