# How to apply an Analyzer to many Indices?

**URL:** <https://discuss.elastic.co/t/how-to-apply-an-analyzer-to-many-indices/82763>\
**Category:** Elasticsearch\
**Created:** [April 18, 2017, 6:43pm UTC](https://discuss.elastic.co/t/how-to-apply-an-analyzer-to-many-indices/82763 "2017-04-18T18:43:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![boCyrill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bocyrill/32/17114_2.png) [@boCyrill](https://discuss.elastic.co/u/boCyrill)\
**Post date:** [April 18, 2017, 6:43pm UTC](https://discuss.elastic.co/t/how-to-apply-an-analyzer-to-many-indices/82763/1 "2017-04-18T18:43:33Z")

</div>

Hello Everyone.  
Need help.  
Am newby to elasticsearch. I have installed ES 5.1.1 and it works great. I use logstash 5.1.1 to index data from a MySQL database to populate 2 ES indices.  
My users are mostly francophone and I have an issue with queries containing accents.  
I read many books and found that the asciifolding filter could help.

I learned how to create analyzer using JSON template file. Here is the content of my job\_template.json file that I want to apply.  
{  
"template": "job\_template",  
"settings": {  
"index": {  
"analysis": {  
"analyzer": {  
"myCustomAnalyzer": {  
"tokenizer": "standard",  
"filter": ["standard", "lowercase", "asciifolding"]  
}  
}  
}  
}  
}  
}

But I am a bit confused on how to achieve this.  
Now my questions are:

1. When to apply an analyzer to ES (before or after indexing)?
2. If it should be before indexing how can I use that configuration into my logstash config file to startup Logstash when I run this command logstash -f conf-logstash.conf ?

The folowing the content of the file conf-logstash.conf  
input {  
jdbc {  
jdbc\_driver\_library =\> "mysql-connector-java-5.1.40-bin.jar"  
jdbc\_driver\_class =\> "com.mysql.jdbc.Driver"  
jdbc\_connection\_string =\> "jdbc:mysql://localhost:3306/appp-dev"  
jdbc\_user =\> "root"  
jdbc\_password =\> "cyrilb"

```
schedule => "* * * * *" #A la 5ieme minutes de chaque heure . Plus de details ici http://www.thegeekstuff.com/2011/07/cron-every-5-minutes/
# Pagination. Logstash chargera les donnees de 50000 en 50000
jdbc_paging_enabled => true
jdbc_page_size => "5000"
# Mettre cette valeur a true si on desir charger a chaque lancement de logstash la BD. Tres utilise apres avoir vider elasticsearch
clean_run => true
statement => "SELECT uid, creation_date, phone, dial_code, email, username, first_name, last_name, gender, title, country, language from doopins WHERE update_date > :sql_last_value"
  }
 }

filter {
  #...
}

```

output {  
stdout { codec =\> json\_lines }  
elasticsearch {  
hosts =\> "localhost:8270"  
document\_id =\> "%{uid}"  
index =\> "test-index"  
document\_type =\> "users"  
}  
}

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 18, 2017, 11:08pm UTC](https://discuss.elastic.co/t/how-to-apply-an-analyzer-to-many-indices/82763/2 "2017-04-18T23:08:53Z")

</div>

> [@boCyrill](#):
>
> 1. When to apply an analyzer to ES (before or after indexing)?

Before.

> [@boCyrill](#):
>
> 1. If it should be before indexing how can I use that configuration into my logstash config file to startup Logstash when I run this command

You can set a template that LS reads - [Elasticsearch output plugin | Logstash Reference [8.11] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-template) - and then put your template path in there.

Or upload the template to ES prior to starting LS.

---

<div class="post-metadata">

**Author:** ![boCyrill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bocyrill/32/17114_2.png) [@boCyrill](https://discuss.elastic.co/u/boCyrill)\
**Post date:** [April 19, 2017, 1:50am UTC](https://discuss.elastic.co/t/how-to-apply-an-analyzer-to-many-indices/82763/3 "2017-04-19T01:50:33Z")

</div>

Thank You for the reply

> [@warkolm](#):
>
> You can set a template that LS reads - [Elasticsearch output plugin | Logstash Reference [8.11] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-template) - and then put your template path in there.
> 
> Or upload the template to ES prior to starting LS.

I tried both solution already.  
I used php curl to post the template as you can see in these images

 ![](https://us1.discourse-cdn.com/elastic/original/3X/b/e/be3efcc3f92b8eb9f3a4bbdf733a5ff350e9526e.PNG)  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/e/5/e52bf546b32fd264928d378b04648e374047f84b.PNG)

Also I even set it via LS before indexing in the template file. see the following image.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/5/e/5e0cef9600977392465cc35845c7ce21937dddd9.PNG)

If I search for the keyword `secrétaire` I have my records but when I try the keyword `secretaire` I have no result.  
So my question other is : Should I set the analyzer to be used before querying ES (I use query\_string for instance) or the analyzer is set by default since the template already existing in ES

What am I missing here ? I am stuck since more than 5 days just because of this issue 😕

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 19, 2017, 2:12am UTC](https://discuss.elastic.co/t/how-to-apply-an-analyzer-to-many-indices/82763/4 "2017-04-19T02:12:06Z")

</div>

Please don't post pictures of text, they are difficult to read and some people may not be even able to see them 🙂

Looking at the `_template` request in your browser, you need to fix the `"template": "doojob_template"` value so that it matches the name of the index, ie `doojob`.

---

<div class="post-metadata">

**Author:** ![boCyrill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bocyrill/32/17114_2.png) [@boCyrill](https://discuss.elastic.co/u/boCyrill)\
**Post date:** [April 19, 2017, 9:19am UTC](https://discuss.elastic.co/t/how-to-apply-an-analyzer-to-many-indices/82763/5 "2017-04-19T09:19:01Z")

</div>

Still no change even after this update 😕  
Here is my new template  
{  
"template": "doojob",  
"settings": {  
"index": {  
"analysis": {  
"analyzer": {  
"myCustomAnalyzer": {  
"tokenizer": "standard",  
"filter": ["standard", "lowercase", "asciifolding"]  
}  
}  
}  
}  
}  
}

---

<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:** [May 17, 2017, 9:26am UTC](https://discuss.elastic.co/t/how-to-apply-an-analyzer-to-many-indices/82763/6 "2017-05-17T09:26:17Z")

</div>

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