# Prefix query search words rather than sentence

**URL:** <https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587>\
**Category:** Elasticsearch\
**Created:** [September 13, 2013, 6:48am UTC](https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587 "2013-09-13T06:48:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)\
**Post date:** [September 13, 2013, 6:48am UTC](https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587/1 "2013-09-13T06:48:19Z")

</div>

Hi All,

I m trying to build a query to search all documents starts with single  
alphabets eg : A

{  
"query" : {  
"prefix" : {  
"DISPLAY\_NAME" : "a"

```
  }}

```

}

However the result returned is

"DISPLAY\_NAME": "Ndek Te Angenan (Lombok)",

It seems like it is search every single words rather than the whole  
sentence.

Anyway that i could search the document that only have single occurence of  
'A' in the 1st letter ?

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 13, 2013, 6:56am UTC](https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587/2 "2013-09-13T06:56:28Z")

</div>

It's because you are using default analyzer which break phrases into words then index them.  
You need to change your mapping here.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 13 sept. 2013 à 08:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :

Hi All,

I m trying to build a query to search all documents starts with single alphabets eg : A

{  
"query" : {  
"prefix" : {  
"DISPLAY\_NAME" : "a"

```
  }}

```

}

However the result returned is

"DISPLAY\_NAME": "Ndek Te Angenan (Lombok)",

It seems like it is search every single words rather than the whole sentence.

Anyway that i could search the document that only have single occurence of 'A' in the 1st letter ?

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).  
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:** ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)\
**Post date:** [September 13, 2013, 7:15am UTC](https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587/3 "2013-09-13T07:15:04Z")

</div>

How do i change the mapping ? and do i need to delete and reindex ? because  
i have millions of records there ?

On Fri, Sep 13, 2013 at 2:56 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> It's because you are using default analyzer which break phrases into words  
> then index them.  
> You need to change your mapping here.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 13 sept. 2013 à 08:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> 
> Hi All,
> 
> I m trying to build a query to search all documents starts with single  
> alphabets eg : A
> 
> {  
> "query" : {  
> "prefix" : {  
> "DISPLAY\_NAME" : "a"
> 
> ```
> }}
> 
> ```
> 
> }
> 
> However the result returned is
> 
> "DISPLAY\_NAME": "Ndek Te Angenan (Lombok)",
> 
> It seems like it is search every single words rather than the whole  
> sentence.
> 
> Anyway that i could search the document that only have single occurence of  
> 'A' in the 1st letter ?
> 
> 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).
> 
> 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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j\_k/unsubscribe](https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j_k/unsubscribe).  
> To unsubscribe from this group and all its topics, 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).

--  
Regards,

Chee Hoo

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 13, 2013, 7:23am UTC](https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587/4 "2013-09-13T07:23:25Z")

</div>

You change the mapping using PUT Mapping API: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/)  
See also: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/) and [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/)

My bet here (I don't have much info about your use case) is that you somehow need a Simple Analyzer [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/simple-analyzer/)

You can use multifield as well to keep your current mapping as is and add another one: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/)

3 choices from there:  
Delete your index, Reindex: you will have a fresh clean new index (you don't need multi field)  
Update the mapping, Reindex (aka Update each document): each document will have a new version  
Update the mapping: only new indexed documents will benefit from this new analyzer

Does it help?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 13 sept. 2013 à 09:15, chee hoo lum [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :

> How do i change the mapping ? and do i need to delete and reindex ? because i have millions of records there ?
> 
> On Fri, Sep 13, 2013 at 2:56 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> It's because you are using default analyzer which break phrases into words then index them.  
> You need to change your mapping here.
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 13 sept. 2013 à 08:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> 
> Hi All,
> 
> I m trying to build a query to search all documents starts with single alphabets eg : A
> 
> {  
> "query" : {  
> "prefix" : {  
> "DISPLAY\_NAME" : "a"
> 
> ```
> }}
> 
> ```
> 
> }
> 
> However the result returned is
> 
> "DISPLAY\_NAME": "Ndek Te Angenan (Lombok)",
> 
> It seems like it is search every single words rather than the whole sentence.
> 
> Anyway that i could search the document that only have single occurence of 'A' in the 1st letter ?
> 
> 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).
> 
> 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 a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j\_k/unsubscribe](https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j_k/unsubscribe).  
> To unsubscribe from this group and all its topics, 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).
> 
> --  
> Regards,
> 
> Chee Hoo
> 
> --  
> 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:** ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)\
**Post date:** [September 13, 2013, 8:07am UTC](https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587/5 "2013-09-13T08:07:27Z")

</div>

Hi David,

First of all thanks.  
Basically what i wanted is only search a particular field that have a  
prefix of eg : 'A' in 1st letter.

More example :

{  
"query" : {  
"prefix" : {  
"DISPLAY\_NAME" : "a"

```
  }}

```

}

Result expected to return is :

1. "DISPLAY\_NAME": "Adele Sings", //YES

2)"DISPLAY\_NAME": "Alex Dance", // YES

3)"DISPLAY\_NAME": "Ndek Te Angenan (Lombok)", //NO

4)"DISPLAY\_NAME": "Ndek Ae Tngenan (Lombok)", //NO

5)"DISPLAY\_NAME": "NAek ee Tngenan (Lombok)", //NO

More comment inlined in red in your previous replies.

Thanks.

On Fri, Sep 13, 2013 at 3:23 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> You change the mapping using PUT Mapping API:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/)  
> See also: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/) and  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/)
> 
> My bet here (I don't have much info about your use case) is that you  
> somehow need a Simple Analyzer  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/simple-analyzer/)

This doesn't explain how i gonna apply the analzyer to the field nor how  
to create an analyzer.

> You can use multifield as well to keep your current mapping as is and add  
> another one:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/)
> 
> 3 choices from there:
> 
> - Delete your index, Reindex: you will have a fresh clean new index  
> (you don't need multi field)

data.

> - Update the mapping, Reindex (aka Update each document): each  
> document will have a new version

will replace each at a time ?

> - Update the mapping: only new indexed documents will benefit from  
> this new analyzer

> Does it help?
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 13 sept. 2013 à 09:15, chee hoo lum [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> 
> How do i change the mapping ? and do i need to delete and reindex ?  
> because i have millions of records there ?
> 
> On Fri, Sep 13, 2013 at 2:56 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > It's because you are using default analyzer which break phrases into  
> > words then index them.  
> > You need to change your mapping here.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 13 sept. 2013 à 08:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> > 
> > Hi All,
> > 
> > I m trying to build a query to search all documents starts with single  
> > alphabets eg : A
> > 
> > {  
> > "query" : {  
> > "prefix" : {  
> > "DISPLAY\_NAME" : "a"
> > 
> > ```
> > }}
> > 
> > ```
> > 
> > }
> > 
> > However the result returned is
> > 
> > "DISPLAY\_NAME": "Ndek Te Angenan (Lombok)",
> > 
> > It seems like it is search every single words rather than the whole  
> > sentence.
> > 
> > Anyway that i could search the document that only have single occurence  
> > of 'A' in the 1st letter ?
> > 
> > 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).
> > 
> > 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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j\_k/unsubscribe](https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j_k/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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).
> 
> --  
> Regards,
> 
> Chee Hoo
> 
> --  
> 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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j\_k/unsubscribe](https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j_k/unsubscribe).  
> To unsubscribe from this group and all its topics, 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).

--  
Regards,

Chee Hoo

--  
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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 13, 2013, 8:29am UTC](https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587/6 "2013-09-13T08:29:47Z")

</div>

Something like:

curl -XPOST "[http://localhost:9200/yourindex/yourtype/\_mapping](http://localhost:9200/yourindex/yourtype/_mapping)" -d '  
{  
"yourtype":{  
"properties":{  
"yourfield":{  
"type":"multi\_field",  
"fields":{  
"yourfield":{"type":"string"},  
"simple":{"type":"string","analyzer":"simple"}  
}  
}  
}  
}  
}  
'

> Doing this will not delete all the current documents and it will replace each at a time ?  
> Behind the scene, yes. It will create a new version of your doc.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 13 sept. 2013 à 10:07, chee hoo lum [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :

> Hi David,
> 
> First of all thanks.  
> Basically what i wanted is only search a particular field that have a prefix of eg : 'A' in 1st letter.
> 
> More example :
> 
> {  
> "query" : {  
> "prefix" : {  
> "DISPLAY\_NAME" : "a"
> 
> ```
> }}
> 
> ```
> 
> }
> 
> Result expected to return is :
> 
> 1. "DISPLAY\_NAME": "Adele Sings", //YES
> 
> 2)"DISPLAY\_NAME": "Alex Dance", // YES
> 
> 3)"DISPLAY\_NAME": "Ndek Te Angenan (Lombok)", //NO
> 
> 4)"DISPLAY\_NAME": "Ndek Ae Tngenan (Lombok)", //NO
> 
> 5)"DISPLAY\_NAME": "NAek ee Tngenan (Lombok)", //NO
> 
> More comment inlined in red in your previous replies.
> 
> Thanks.
> 
> On Fri, Sep 13, 2013 at 3:23 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> You change the mapping using PUT Mapping API: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/)  
> See also: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/) and [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/)
> 
> My bet here (I don't have much info about your use case) is that you somehow need a Simple Analyzer [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/simple-analyzer/)
> 
> This doesn't explain how i gonna apply the analzyer to the field nor how to create an analyzer.
> 
> You can use multifield as well to keep your current mapping as is and add another one: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/)
> 
> 3 choices from there:  
> Delete your index, Reindex: you will have a fresh clean new index (you don't need multi field)  
> This might not be my best choice due to developers need the data.  
> Update the mapping, Reindex (aka Update each document): each document will have a new version  
> Doing this will not delete all the current documents and it will replace each at a time ?
> 
> Update the mapping: only new indexed documents will benefit from this new analyzer  
> Not smtg i wanted to 🙂
> 
> Does it help?
> 
> --  
> David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
> @dadoonet | @elasticsearchfr | @scrutmydocs
> 
> Le 13 sept. 2013 à 09:15, chee hoo lum [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> 
> > How do i change the mapping ? and do i need to delete and reindex ? because i have millions of records there ?
> > 
> > On Fri, Sep 13, 2013 at 2:56 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:  
> > It's because you are using default analyzer which break phrases into words then index them.  
> > You need to change your mapping here.
> > 
> > --  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > 
> > Le 13 sept. 2013 à 08:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> > 
> > Hi All,
> > 
> > I m trying to build a query to search all documents starts with single alphabets eg : A
> > 
> > {  
> > "query" : {  
> > "prefix" : {  
> > "DISPLAY\_NAME" : "a"
> > 
> > ```
> > }}
> > 
> > ```
> > 
> > }
> > 
> > However the result returned is
> > 
> > "DISPLAY\_NAME": "Ndek Te Angenan (Lombok)",
> > 
> > It seems like it is search every single words rather than the whole sentence.
> > 
> > Anyway that i could search the document that only have single occurence of 'A' in the 1st letter ?
> > 
> > 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).
> > 
> > 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 a topic in the Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j\_k/unsubscribe](https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j_k/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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).
> > 
> > --  
> > Regards,
> > 
> > Chee Hoo
> > 
> > --  
> > 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 a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j\_k/unsubscribe](https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j_k/unsubscribe).  
> To unsubscribe from this group and all its topics, 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).
> 
> --  
> Regards,
> 
> Chee Hoo
> 
> --  
> 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:** ![cyrilforce](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cyrilforce](https://discuss.elastic.co/u/cyrilforce)\
**Post date:** [September 13, 2013, 8:52am UTC](https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587/7 "2013-09-13T08:52:57Z")

</div>

Hi David,

Thanks alot. I will tried it. Sorry for asking such detail due to the  
urgency and too many tasks on my hand. 🙂  
Appreciate your help.

Cyril

On Fri, Sep 13, 2013 at 4:29 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Something like:
> 
> curl -XPOST "[http://localhost:9200/yourindex/yourtype/\_mapping](http://localhost:9200/yourindex/yourtype/_mapping)" -d '  
> {  
> "yourtype":{  
> "properties":{  
> "yourfield":{  
> "type":"multi\_field",  
> "fields":{  
> "yourfield":{"type":"string"},  
> "simple":{"type":"string","analyzer":"simple"}  
> }  
> }  
> }  
> }  
> }  
> '
> 
> > Doing this will not delete all the current documents and it will  
> > replace each at a time ?  
> > Behind the scene, yes. It will create a new version of your doc.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 13 sept. 2013 à 10:07, chee hoo lum [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> 
> Hi David,
> 
> First of all thanks.  
> Basically what i wanted is only search a particular field that have a  
> prefix of eg : 'A' in 1st letter.
> 
> More example :
> 
> {  
> "query" : {  
> "prefix" : {  
> "DISPLAY\_NAME" : "a"
> 
> ```
> }}
> 
> ```
> 
> }
> 
> Result expected to return is :
> 
> 1. "DISPLAY\_NAME": "Adele Sings", //YES
> 
> 2)"DISPLAY\_NAME": "Alex Dance", // YES
> 
> 3)"DISPLAY\_NAME": "Ndek Te Angenan (Lombok)", //NO
> 
> 4)"DISPLAY\_NAME": "Ndek Ae Tngenan (Lombok)", //NO
> 
> 5)"DISPLAY\_NAME": "NAek ee Tngenan (Lombok)", //NO
> 
> More comment inlined in red in your previous replies.
> 
> Thanks.
> 
> On Fri, Sep 13, 2013 at 3:23 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > You change the mapping using PUT Mapping API:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/)  
> > See also: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/) and  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/)
> > 
> > My bet here (I don't have much info about your use case) is that you  
> > somehow need a Simple Analyzer  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/index-modules/analysis/simple-analyzer/)
> 
> This doesn't explain how i gonna apply the analzyer to the field nor  
> how to create an analyzer.
> 
> > You can use multifield as well to keep your current mapping as is and add  
> > another one:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/)
> > 
> > 3 choices from there:
> > 
> > - Delete your index, Reindex: you will have a fresh clean new index  
> > (you don't need multi field)
> 
> data.
> 
> > - Update the mapping, Reindex (aka Update each document): each  
> > document will have a new version
> 
> will replace each at a time ?
> 
> > - Update the mapping: only new indexed documents will benefit from  
> > this new analyzer
> 
> > Does it help?
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | \*[Elasticsearch.com](http://Elasticsearch.com)[http://elasticsearch.com/](http://elasticsearch.com/)  
> > \*  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > 
> > Le 13 sept. 2013 à 09:15, chee hoo lum [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> > 
> > How do i change the mapping ? and do i need to delete and reindex ?  
> > because i have millions of records there ?
> > 
> > On Fri, Sep 13, 2013 at 2:56 PM, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > 
> > > It's because you are using default analyzer which break phrases into  
> > > words then index them.  
> > > You need to change your mapping here.
> > > 
> > > --  
> > > David 😉  
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > Le 13 sept. 2013 à 08:48, cyrilforce [cheehoo84@gmail.com](mailto:cheehoo84@gmail.com) a écrit :
> > > 
> > > Hi All,
> > > 
> > > I m trying to build a query to search all documents starts with single  
> > > alphabets eg : A
> > > 
> > > {  
> > > "query" : {  
> > > "prefix" : {  
> > > "DISPLAY\_NAME" : "a"
> > > 
> > > ```
> > > }}
> > > 
> > > ```
> > > 
> > > }
> > > 
> > > However the result returned is
> > > 
> > > "DISPLAY\_NAME": "Ndek Te Angenan (Lombok)",
> > > 
> > > It seems like it is search every single words rather than the whole  
> > > sentence.
> > > 
> > > Anyway that i could search the document that only have single occurence  
> > > of 'A' in the 1st letter ?
> > > 
> > > 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).
> > > 
> > > 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 a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j\_k/unsubscribe](https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j_k/unsubscribe).  
> > > To unsubscribe from this group and all its topics, 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).
> > 
> > --  
> > Regards,
> > 
> > Chee Hoo
> > 
> > --  
> > 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 a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j\_k/unsubscribe](https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j_k/unsubscribe).  
> > To unsubscribe from this group and all its topics, 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).
> 
> --  
> Regards,
> 
> Chee Hoo
> 
> --  
> 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 a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j\_k/unsubscribe](https://groups.google.com/d/topic/elasticsearch/xOmcYMr8j_k/unsubscribe).  
> To unsubscribe from this group and all its topics, 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).

--  
Regards,

Chee Hoo

--  
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:16am UTC](https://discuss.elastic.co/t/prefix-query-search-words-rather-than-sentence/13587/8 "2017-07-06T02:16:40Z")

</div>


