# PHP example not working

**URL:** <https://discuss.elastic.co/t/php-example-not-working/34942>\
**Category:** Elasticsearch\
**Created:** [November 18, 2015, 1:58pm UTC](https://discuss.elastic.co/t/php-example-not-working/34942 "2015-11-18T13:58:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tybreizh29190](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tybreizh29190](https://discuss.elastic.co/u/tybreizh29190)\
**Post date:** [November 18, 2015, 1:58pm UTC](https://discuss.elastic.co/t/php-example-not-working/34942/1 "2015-11-18T13:58:12Z")

</div>

Hello  
in this page :  
[https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/\_index\_management\_operations.html#\_put\_settings\_api](https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_index_management_operations.html#_put_settings_api)

I try this example :

> $client = ClientBuilder::create()-\>build();  
> $params = [  
> 'index' =\> 'my\_index',  
> 'body' =\> [  
> 'settings' =\> [  
> 'number\_of\_shards' =\> 3,  
> 'number\_of\_replicas' =\> 2  
> ],  
> 'mappings' =\> [  
> 'my\_type' =\> [  
> '\_source' =\> [  
> 'enabled' =\> true,  
> 'properties' =\> [  
> 'first\_name' =\> [  
> 'type' =\> 'string',  
> 'analyzer' =\> 'standard'  
> ],  
> 'age' =\> [  
> 'type' =\> 'integer'  
> ]  
> ]  
> ]  
> ]  
> ]  
> ]  
> ];

> // Create the index with mappings and settings now  
> $response = $client-\>indices()-\>create($params);

and I get an exception :

> PHP Fatal error: Uncaught exception 'Elasticsearch\Common\Exceptions\BadRequest400Exception' with message '{"error":{"root\_cause":[{"type":"mapper\_parsing\_exception","reason":"Mapping definition for [\_source] has unsupported parameters: [properties : {first\_name={analyzer=standard, type=string}, age={type=integer}}]"}],"type":"mapper\_parsing\_exception","reason":"mapping [my\_type]","caused\_by":{"type":"mapper\_parsing\_exception","reason":"Mapping definition for [\_source] has unsupported parameters: [properties : {first\_name={analyzer=standard, type=string}, age={type=integer}}]"}},"status":400}' in /opt/MSF/development/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:613\nStack trace:\n#0 /opt/MSF/development/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(590): Elasticsearch\Connections\Connection-\>tryDeserializeError(Array, 'Elasticsearch\\C...')\n#1 /opt/MSF/development/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Con in /opt/MSF/development/www/html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 615

what would be the right syntax, the first example of the tutorial works.  
My version is 2.0.0  
I'm a total newbee.  
thank for helping me.  
marc

---

<div class="post-metadata">

**Author:** ![rusty](https://avatars.discourse-cdn.com/v4/letter/r/f17d59/32.png) [@rusty](https://discuss.elastic.co/u/rusty)\
**Post date:** [November 18, 2015, 2:17pm UTC](https://discuss.elastic.co/t/php-example-not-working/34942/2 "2015-11-18T14:17:45Z")

</div>

Hi, Marc. Look at this example in [Put Mappings API](https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_index_management_operations.html#_put_mappings_api), maybe you should use this API to change index mapping.  
In your example the `_source` and `properties` must not be nested.

---

<div class="post-metadata">

**Author:** ![tybreizh29190](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@tybreizh29190](https://discuss.elastic.co/u/tybreizh29190)\
**Post date:** [November 18, 2015, 2:37pm UTC](https://discuss.elastic.co/t/php-example-not-working/34942/3 "2015-11-18T14:37:00Z")

</div>

Hi Rusty  
That's it  
the Example should be :

> $params = [  
> 'index' =\> 'my\_index',  
> 'body' =\> [  
> 'settings' =\> [  
> 'number\_of\_shards' =\> 3,  
> 'number\_of\_replicas' =\> 2  
> ],  
> 'mappings' =\> [  
> 'my\_type' =\> [  
> '\_source' =\> [  
> 'enabled' =\> true  
> ],  
> 'properties' =\> [  
> 'first\_name' =\> [  
> 'type' =\> 'string',  
> 'analyzer' =\> 'standard'  
> ],  
> 'age' =\> [  
> 'type' =\> 'integer'  
> ]  
> ]  
> ]  
> ]  
> ]  
> ];

thank you very much  
marc

---

<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:** [July 5, 2017, 11:37pm UTC](https://discuss.elastic.co/t/php-example-not-working/34942/4 "2017-07-05T23:37:36Z")

</div>


