# Analyzer on indexed documents

**URL:** <https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596>\
**Category:** Elasticsearch\
**Created:** [November 14, 2018, 7:25am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596 "2018-11-14T07:25:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zahra\_Aminolroaya](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@Zahra\_Aminolroaya](https://discuss.elastic.co/u/Zahra_Aminolroaya)\
**Post date:** [November 14, 2018, 7:25am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/1 "2018-11-14T07:25:23Z")

</div>

I am new to elastic. I want to test phonetic in my documents. I used the link below to test phonetic:  
[phonetic](https://www.elastic.co/guide/en/elasticsearch/plugins/2.1/analysis-phonetic-token-filter.html)

I tested the analyzer and I got the same result. However, in this example, you should give the text field. I want the analyzer automatically be applied in my index documents. What should I do?

---

<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:** [November 14, 2018, 7:46am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/2 "2018-11-14T07:46:48Z")

</div>

Ideally, analysers are applied to documents during indexing, so you should reindex.  
Alternatively you can try [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyzer.html)

Also, you linked to 2.1, are you running that older version?

---

<div class="post-metadata">

**Author:** ![Zahra\_Aminolroaya](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@Zahra\_Aminolroaya](https://discuss.elastic.co/u/Zahra_Aminolroaya)\
**Post date:** [November 14, 2018, 8:12am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/3 "2018-11-14T08:12:18Z")

</div>

Thanks mark. I use the last version. Based on the link I provide I search like this:

GET phonetic\_sample/\_search  
{  
"query": {  
"match": {  
"text": {  
"query": "BLKS"  
}  
}  
}  
}

I expect the elastic return

"hits": {  
"total": 1,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "phonetic\_sample",  
"\_type": "\_doc",  
"\_id": "1",  
"\_score": 1,  
"\_source": {  
"text": "Joe Bloggs"  
}  
}  
]  
}  
but it returns nothing.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 14, 2018, 8:15am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/4 "2018-11-14T08:15:06Z")

</div>

Please show your mapping for the index, as a lot will depend on what this looks like.

---

<div class="post-metadata">

**Author:** ![Zahra\_Aminolroaya](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@Zahra\_Aminolroaya](https://discuss.elastic.co/u/Zahra_Aminolroaya)\
**Post date:** [November 14, 2018, 8:16am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/5 "2018-11-14T08:16:01Z")

</div>

{  
"mapping": {  
"\_doc": {  
"properties": {  
"text": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},  
"user": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 14, 2018, 8:18am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/6 "2018-11-14T08:18:20Z")

</div>

It looks like you are using standard dynamic mappings and have not specified any custom analysers. That means that your query will match tokens using the standard analyzer, and that does not include any phonetic analysis, which is why your query does not return any results.

---

<div class="post-metadata">

**Author:** ![Zahra\_Aminolroaya](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@Zahra\_Aminolroaya](https://discuss.elastic.co/u/Zahra_Aminolroaya)\
**Post date:** [November 14, 2018, 8:20am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/7 "2018-11-14T08:20:52Z")

</div>

but when I use this:

GET phonetic\_sample/\_analyze { "analyzer": "my\_analyzer", "text": "Joe Bloggs" }

I get the below result:

{  
"tokens": [  
{  
"token": "J",  
"start\_offset": 0,  
"end\_offset": 3,  
"type": "",  
"position": 0  
},  
{  
"token": "joe",  
"start\_offset": 0,  
"end\_offset": 3,  
"type": "",  
"position": 0  
},  
{  
"token": "BLKS",  
"start\_offset": 4,  
"end\_offset": 10,  
"type": "",  
"position": 1  
},  
{  
"token": "bloggs",  
"start\_offset": 4,  
"end\_offset": 10,  
"type": "",  
"position": 1  
},  
{  
"token": "1",  
"start\_offset": 11,  
"end\_offset": 12,  
"type": "",  
"position": 2  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 14, 2018, 8:23am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/8 "2018-11-14T08:23:40Z")

</div>

Yes, but where are you using this analyzer? It is not in your index mapping, so is not applied at index time.

---

<div class="post-metadata">

**Author:** ![Zahra\_Aminolroaya](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@Zahra\_Aminolroaya](https://discuss.elastic.co/u/Zahra_Aminolroaya)\
**Post date:** [November 14, 2018, 8:26am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/9 "2018-11-14T08:26:08Z")

</div>

thanks Christian. I used the link I provided and based on what mark said it should be applied to documents during indexing. I will use his alternative option and tell the result.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 14, 2018, 8:27am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/10 "2018-11-14T08:27:48Z")

</div>

Here I suspect you will need to reindex and apply the analyser at index time. You can phonetically get Bloggs tokenised as BLKS, but not the other way around.

---

<div class="post-metadata">

**Author:** ![Zahra\_Aminolroaya](https://avatars.discourse-cdn.com/v4/letter/z/5f8ce5/32.png) [@Zahra\_Aminolroaya](https://discuss.elastic.co/u/Zahra_Aminolroaya)\
**Post date:** [November 14, 2018, 9:48am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/11 "2018-11-14T09:48:51Z")

</div>

Finally I used the following which solved my problem:

PUT my\_index1  
{  
"settings": {  
"analysis": {  
"filter": {  
"my\_phonetic": {  
"type": "phonetic"  
}  
},  
"analyzer": {  
"my\_phonetic": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": ["phonetic"  
]  
}  
}  
}  
},  
"mappings": {  
"\_doc": {  
"properties": {  
"text": {  
"type": "text",  
"analyzer": "my\_phonetic",  
"search\_analyzer": "my\_phonetic"  
}  
}  
}  
}  
}

---

<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:** [December 12, 2018, 9:49am UTC](https://discuss.elastic.co/t/analyzer-on-indexed-documents/156596/12 "2018-12-12T09:49:03Z")

</div>

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