Create an app search engine from an elasticsearch index using the PHP client

I am currently integrating App search with a PHP project. I am using elasticsearch to index my documents but I use App search to query the documents, by creating engines from the indices. I am trying to use the enterprise search PHP client to automatically they create app search engines, if they don't already exist. But I cannot find a way to do that, in the docs. Is that possible ?
This is my code at the moment. I keep getting a 400 error code:

try {
  $appSearchClient->getEngine(new GetEngine($appSearchEngineName));
} catch (ClientErrorResponseException $e){
  if ($e->getCode() === 404){
    $engine = new Engine($appSearchEngineName);
    $engine->type = 'elasticsearch';
    $appSearchClient->createEngine(new CreateEngine($engine));

Thanks in advance

Hi Francis,
This looks similar to another question that was posted. That user was also receiving 400s when trying to create an elasticsearch type engine. Can you confirm that your configured user has the correct permissions to create engines?

EDIT: here is the documentation for App Search users in case it helps. If permissions are the cause, then the user may need to be owner or admin.

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