# Problem using custom analyzer in mapping field

**URL:** <https://discuss.elastic.co/t/problem-using-custom-analyzer-in-mapping-field/13547>\
**Category:** Elasticsearch\
**Created:** [September 11, 2013, 3:23am UTC](https://discuss.elastic.co/t/problem-using-custom-analyzer-in-mapping-field/13547 "2013-09-11T03:23:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivo\_Sanchez\_Checa\_Cr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivo_sanchez_checa_cr/32/2110_2.png) [@Ivo\_Sanchez\_Checa\_Cr](https://discuss.elastic.co/u/Ivo_Sanchez_Checa_Cr)\
**Post date:** [September 11, 2013, 3:23am UTC](https://discuss.elastic.co/t/problem-using-custom-analyzer-in-mapping-field/13547/1 "2013-09-11T03:23:43Z")

</div>

Hi,

I'm trying to make a prefix query on a field that can hold non-ascii  
spanish characters (i.e áéíóúñ)

I've made a custom analyzer and have added it to a field in my mapping by  
doing:

# create index

curl -XPUT 'elasticsearch:9200/my\_new\_index' -d '{  
"settings": {  
"index": {  
"analysis": {  
"analyzer": {  
"my\_custom\_analyzer": {  
"type": "custom",  
"tokenizer": "keyword",  
"filter": ["asciifolding", "lowercase"]  
}  
}  
}  
}  
}  
}'

# create mapping

curl -XPUT 'elasticsearch:9200/my\_new\_index/my\_mapping/\_mapping' -d '{  
"properties": {  
"guid": {"type": "string", "index": "no"},  
"name": {  
"type": "string",  
"index": "analyzed",  
"analyzer": "my\_custom\_analyzer"  
}  
}  
}'

I can confirm the analyzer is working fine since I've tried it directly  
via the Analyzer API by running:

curl -XGET  
'elasticsearch:9200/my\_new\_index/\_analyze?analyzer=my\_custom\_analyzer' -d  
'áéíóú'

{  
"tokens" : [ {  
"token" : "aeiou",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "word",  
"position" : 1  
} ]  
}

But for some reason, the queries on the mapping are not using the analyzer,  
namely the following query. If I understand correctly it should match  
documents starting with both "aei" and "áéí", but it only matches the  
latter case.

curl -XPOST 'elasticsearch:9200/my\_new\_index/my\_mapping/\_search?pretty=true' -d '{  
"query": {  
"prefix": {  
"name" : {  
"prefix": "áéí"  
}  
}  
}  
}'

What I'm I missing? A full, runnable, example showing the problem can be  
found here: [https://gist.github.com/ivoscc/6518829](https://gist.github.com/ivoscc/6518829)

Thanks a lot for your help!

Ivo

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [September 11, 2013, 7:27am UTC](https://discuss.elastic.co/t/problem-using-custom-analyzer-in-mapping-field/13547/2 "2013-09-11T07:27:32Z")

</div>

Hi,

Prefix queries[1] are not analyzed. You need to pass the prefix as it is  
expected to be stored in the index so that your example works. For example,  
you can run:

curl -XPOST 'elasticsearch:9200/my\_new\_index/my\_mapping/\_search?pretty=true'  
-d '{  
"query": {  
"prefix": {  
"name" : {  
"prefix": "aei"  
}  
}  
}  
}'

[1] [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/prefix-query/)

On Wed, Sep 11, 2013 at 5:23 AM, Ivo Sanchez Checa Crosato \<[ivoscc@gmail.com](mailto:ivoscc@gmail.com)

> wrote:

> Hi,
> 
> I'm trying to make a prefix query on a field that can hold non-ascii  
> spanish characters (i.e áéíóúñ)
> 
> I've made a custom analyzer and have added it to a field in my mapping by  
> doing:
> 
> # create index
> 
> curl -XPUT 'elasticsearch:9200/my\_new\_index' -d '{  
> "settings": {  
> "index": {  
> "analysis": {  
> "analyzer": {  
> "my\_custom\_analyzer": {  
> "type": "custom",  
> "tokenizer": "keyword",  
> "filter": ["asciifolding", "lowercase"]  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> # create mapping
> 
> curl -XPUT 'elasticsearch:9200/my\_new\_index/my\_mapping/\_mapping' -d '{  
> "properties": {  
> "guid": {"type": "string", "index": "no"},  
> "name": {  
> "type": "string",  
> "index": "analyzed",  
> "analyzer": "my\_custom\_analyzer"  
> }  
> }  
> }'
> 
> I can confirm the analyzer is working fine since I've tried it directly  
> via the Analyzer API by running:
> 
> curl -XGET  
> 'elasticsearch:9200/my\_new\_index/\_analyze?analyzer=my\_custom\_analyzer' -d  
> 'áéíóú'
> 
> {  
> "tokens" : [ {  
> "token" : "aeiou",  
> "start\_offset" : 0,  
> "end\_offset" : 5,  
> "type" : "word",  
> "position" : 1  
> } ]  
> }
> 
> But for some reason, the queries on the mapping are not using the  
> analyzer, namely the following query. If I understand correctly it should  
> match documents starting with both "aei" and "áéí", but it only matches the  
> latter case.
> 
> curl -XPOST 'elasticsearch:9200/my\_new\_index/my\_mapping/\_search?pretty=true' -d '{  
> "query": {  
> "prefix": {  
> "name" : {  
> "prefix": "áéí"  
> }  
> }  
> }  
> }'
> 
> What I'm I missing? A full, runnable, example showing the problem can be  
> found here: [gist:6518829 · GitHub](https://gist.github.com/ivoscc/6518829)
> 
> Thanks a lot for your help!
> 
> Ivo
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Adrien Grand

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Britta\_Weber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/britta_weber/32/1113_2.png) [@Britta\_Weber](https://discuss.elastic.co/u/Britta_Weber)\
**Post date:** [September 11, 2013, 7:53am UTC](https://discuss.elastic.co/t/problem-using-custom-analyzer-in-mapping-field/13547/3 "2013-09-11T07:53:23Z")

</div>

Hi,

I think you were missing a line when you put the mapping. Try like this:

# create mapping

curl -XPUT 'elasticsearch:9200/my\_new\_index/my\_mapping/\_mapping' -d '{  
"my\_mapping": {  
"properties": {  
"guid": {"type": "string", "index": "no"},  
"name": {  
"type": "string",  
"index": "analyzed",  
"analyzer": "my\_custom\_analyzer"  
}  
}  
}  
}'

Your example works for me with this modification.

Cheers,  
Britta

On Wed, Sep 11, 2013 at 5:23 AM, Ivo Sanchez Checa Crosato  
[ivoscc@gmail.com](mailto:ivoscc@gmail.com) wrote:

> Hi,
> 
> I'm trying to make a prefix query on a field that can hold non-ascii spanish  
> characters (i.e áéíóúñ)
> 
> I've made a custom analyzer and have added it to a field in my mapping by  
> doing:
> 
> # create index
> 
> curl -XPUT 'elasticsearch:9200/my\_new\_index' -d '{  
> "settings": {  
> "index": {  
> "analysis": {  
> "analyzer": {  
> "my\_custom\_analyzer": {  
> "type": "custom",  
> "tokenizer": "keyword",  
> "filter": ["asciifolding", "lowercase"]  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> # create mapping
> 
> curl -XPUT 'elasticsearch:9200/my\_new\_index/my\_mapping/\_mapping' -d '{  
> "properties": {  
> "guid": {"type": "string", "index": "no"},  
> "name": {  
> "type": "string",  
> "index": "analyzed",  
> "analyzer": "my\_custom\_analyzer"  
> }  
> }  
> }'
> 
> I can confirm the analyzer is working fine since I've tried it directly via  
> the Analyzer API by running:
> 
> curl -XGET  
> 'elasticsearch:9200/my\_new\_index/\_analyze?analyzer=my\_custom\_analyzer' -d  
> 'áéíóú'
> 
> {  
> "tokens" : [ {  
> "token" : "aeiou",  
> "start\_offset" : 0,  
> "end\_offset" : 5,  
> "type" : "word",  
> "position" : 1  
> } ]  
> }
> 
> But for some reason, the queries on the mapping are not using the analyzer,  
> namely the following query. If I understand correctly it should match  
> documents starting with both "aei" and "áéí", but it only matches the latter  
> case.
> 
> curl -XPOST 'elasticsearch:9200/my\_new\_index/my\_mapping/\_search?pretty=true'  
> -d '{  
> "query": {  
> "prefix": {  
> "name" : {  
> "prefix": "áéí"  
> }  
> }  
> }  
> }'
> 
> What I'm I missing? A full, runnable, example showing the problem can be  
> found here: [gist:6518829 · GitHub](https://gist.github.com/ivoscc/6518829)
> 
> Thanks a lot for your help!
> 
> Ivo
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:17am UTC](https://discuss.elastic.co/t/problem-using-custom-analyzer-in-mapping-field/13547/4 "2017-07-06T02:17:11Z")

</div>


