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

**URL:** <https://discuss.elastic.co/t/create-an-app-search-engine-from-an-elasticsearch-index-using-the-php-client/338409>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [July 14, 2023, 11:58am UTC](https://discuss.elastic.co/t/create-an-app-search-engine-from-an-elasticsearch-index-using-the-php-client/338409 "2023-07-14T11:58:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![franmako](https://avatars.discourse-cdn.com/v4/letter/f/3e96dc/32.png) [@franmako](https://discuss.elastic.co/u/franmako)\
**Post date:** [July 14, 2023, 11:58am UTC](https://discuss.elastic.co/t/create-an-app-search-engine-from-an-elasticsearch-index-using-the-php-client/338409/1 "2023-07-14T11:58:00Z")

</div>

Hello,  
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![nfeekery](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nfeekery/32/117349_2.png) [@nfeekery](https://discuss.elastic.co/u/nfeekery)\
**Post date:** [July 20, 2023, 1:23pm UTC](https://discuss.elastic.co/t/create-an-app-search-engine-from-an-elasticsearch-index-using-the-php-client/338409/2 "2023-07-20T13:23:36Z")

</div>

Hi Francis,  
This looks similar to [another question that was posted](https://discuss.elastic.co/t/app-search-error-create-engine/326827). That user was also receiving `400`s 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](https://www.elastic.co/guide/en/app-search/8.8/security-and-users.html#security-roles-engines) in case it helps. If permissions are the cause, then the user may need to be owner or admin.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 17, 2023, 1:23pm UTC](https://discuss.elastic.co/t/create-an-app-search-engine-from-an-elasticsearch-index-using-the-php-client/338409/3 "2023-08-17T13:23:51Z")

</div>

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