# Custom analyzers with elasticsearch-php API

**URL:** <https://discuss.elastic.co/t/custom-analyzers-with-elasticsearch-php-api/18261>\
**Category:** Elasticsearch\
**Created:** [June 23, 2014, 12:44pm UTC](https://discuss.elastic.co/t/custom-analyzers-with-elasticsearch-php-api/18261 "2014-06-23T12:44:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivier\_Revollat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olivier_revollat/32/1467_2.png) [@Olivier\_Revollat](https://discuss.elastic.co/u/Olivier_Revollat)\
**Post date:** [June 23, 2014, 12:44pm UTC](https://discuss.elastic.co/t/custom-analyzers-with-elasticsearch-php-api/18261/1 "2014-06-23T12:44:49Z")

</div>

Hello I currently creating an elasticsearch extension for Bolt (a [very  
cool] symfony2 based CMS).  
For the PHP client i'm using elasticsearch-php.

Great ! I already wrote the code that create the index, mapping and add  
some data 🙂

Now I would like to customize the analyzer, so OK in the mapping I could  
tell (as described in  
[http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/\_index\_operations.html](http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_index_operations.html))  
:

$myTypeMapping = array(  
'\_source' =\> array(  
'enabled' =\> true  
),  
'properties' =\> array(  
'first\_name' =\> array(  
'type' =\> 'string',  
'analyzer' =\> '_whatever\_analyzer_'  
),  
'age' =\> array(  
'type' =\> 'integer'  
)  
)  
);

But I don't really understand\* how/where to declare the so called \*\*whatever\_analyzer  
\*Instead of the default "standard" analyzer ... can you point me to the  
example in the documentation ?

For example, if I want this kind of analyzers, how ca I declare this with  
elasticsearch-php ?

```
                    analyzer:
                        default_index:
                            type: "custom"
                            char_filter: html_strip
                            tokenizer: "standard" # 

```

"my\_edge\_ngram\_tokenizer"  
filter: [ trim, lowercase, stop\_fr,  
fr\_stemmer, my\_edge\_ngram\_filter, asciifolding ]  
default\_search:  
type: custom  
tokenizer: standard  
filter: [ trim, lowercase, stop\_fr,  
fr\_stemmer, asciifolding ]  
mots\_clefs:  
type: "custom"  
tokenizer: "keyword"  
filter: [ standard, trim, lowercase,  
asciifolding ]  
filter:  
my\_edge\_ngram\_filter:  
type: "edgeNGram"  
min\_gram: "3"  
max\_gram: "20"  
stop\_fr:  
type: "stop"  
stopwords: [_french_]  
fr\_stemmer:  
type: "stemmer"  
name: "french"

Thanks 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0a9cd8f0-a6ac-473f-b090-9cff90fa9fa3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0a9cd8f0-a6ac-473f-b090-9cff90fa9fa3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Olivier\_Revollat](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/olivier_revollat/32/1467_2.png) [@Olivier\_Revollat](https://discuss.elastic.co/u/Olivier_Revollat)\
**Post date:** [June 24, 2014, 9:38am UTC](https://discuss.elastic.co/t/custom-analyzers-with-elasticsearch-php-api/18261/2 "2014-06-24T09:38:30Z")

</div>

I publish my own answer 🙂

so following the exemple

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

you can add custom analyzers simply at the index creation 🙂

```
    $indexParams['body'] = $this->config['indexsetting'];
    $result = $this->client->indices()->create($indexParams);

```

given that for example, $this-\>config['indexsetting'] is the following yaml  
(that have to be converted in php array) :

indexsetting:  
analysis:  
analyzer:  
nom\_analyzer:  
type: custom  
tokenizer: standard  
filter: [trim, lowercase, asciifolding]

Le lundi 23 juin 2014 14:44:49 UTC+2, Olivier Revollat a écrit :

> Hello I currently creating an elasticsearch extension for Bolt (a [very  
> cool] symfony2 based CMS).  
> For the PHP client i'm using elasticsearch-php.
> 
> Great ! I already wrote the code that create the index, mapping and add  
> some data 🙂
> 
> Now I would like to customize the analyzer, so OK in the mapping I could  
> tell (as described in  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/_index_operations.html))  
> :
> 
> $myTypeMapping = array(  
> '\_source' =\> array(  
> 'enabled' =\> true  
> ),  
> 'properties' =\> array(  
> 'first\_name' =\> array(  
> 'type' =\> 'string',  
> 'analyzer' =\> '_whatever\_analyzer_'  
> ),  
> 'age' =\> array(  
> 'type' =\> 'integer'  
> )  
> )  
> );
> 
> But I don't really understand\* how/where to declare the so called \*\*whatever\_analyzer  
> \*Instead of the default "standard" analyzer ... can you point me to the  
> example in the documentation ?
> 
> For example, if I want this kind of analyzers, how ca I declare this with  
> elasticsearch-php ?
> 
> ```
> analyzer:
> default_index:
> type: "custom"
> char_filter: html_strip
> tokenizer: "standard" # 
> 
> ```
> 
> "my\_edge\_ngram\_tokenizer"  
> filter: [ trim, lowercase, stop\_fr,  
> fr\_stemmer, my\_edge\_ngram\_filter, asciifolding ]  
> default\_search:  
> type: custom  
> tokenizer: standard  
> filter: [ trim, lowercase, stop\_fr,  
> fr\_stemmer, asciifolding ]  
> mots\_clefs:  
> type: "custom"  
> tokenizer: "keyword"  
> filter: [ standard, trim, lowercase,  
> asciifolding ]  
> filter:  
> my\_edge\_ngram\_filter:  
> type: "edgeNGram"  
> min\_gram: "3"  
> max\_gram: "20"  
> stop\_fr:  
> type: "stop"  
> stopwords: [_french_]  
> fr\_stemmer:  
> type: "stemmer"  
> name: "french"
> 
> Thanks 🙂

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c8528a5d-18e5-4017-9708-329ab133386d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c8528a5d-18e5-4017-9708-329ab133386d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:20am UTC](https://discuss.elastic.co/t/custom-analyzers-with-elasticsearch-php-api/18261/3 "2017-07-06T01:20:16Z")

</div>


