# Prefix ending in dot

**URL:** <https://discuss.elastic.co/t/prefix-ending-in-dot/6326>\
**Category:** Elasticsearch\
**Created:** [January 9, 2012, 2:20pm UTC](https://discuss.elastic.co/t/prefix-ending-in-dot/6326 "2012-01-09T14:20:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Sakkis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/george_sakkis/32/2801_2.png) [@George\_Sakkis](https://discuss.elastic.co/u/George_Sakkis)\
**Post date:** [January 9, 2012, 2:20pm UTC](https://discuss.elastic.co/t/prefix-ending-in-dot/6326/1 "2012-01-09T14:20:04Z")

</div>

Hi all,

it looks like searching for a prefix that ends in a dot does not find  
documents where a term matches exactly the prefix. Here's an example:

curl -XDELETE '[http://localhost:9200/test](http://localhost:9200/test)'  
curl -XPUT '[http://localhost:9200/test/](http://localhost:9200/test/)'

curl -XPUT '[http://localhost:9200/test/country/1](http://localhost:9200/test/country/1)' -d '{"name": "US of  
A"}'  
curl -XPUT '[http://localhost:9200/test/country/2](http://localhost:9200/test/country/2)' -d '{"name": "USA"}'

curl -XPUT '[http://localhost:9200/test/country/3](http://localhost:9200/test/country/3)' -d '{"name": "U.S of  
A"}'  
curl -XPUT '[http://localhost:9200/test/country/4](http://localhost:9200/test/country/4)' -d '{"name": "U.S.  
of A"}'  
curl -XPUT '[http://localhost:9200/test/country/5](http://localhost:9200/test/country/5)' -d '{"name":  
"U.S.A"}'

curl -XPOST '[http://localhost:9200/test/\_refresh](http://localhost:9200/test/_refresh)'

# finds (1) and (2): ok

curl -s '[http://localhost:9200/test/country/\_search?pretty=true](http://localhost:9200/test/country/_search?pretty=true)' -d  
'{"query": {"prefix": {"name": "us"}}}'

# finds (3), (4) and (5): ok

curl -s '[http://localhost:9200/test/country/\_search?pretty=true](http://localhost:9200/test/country/_search?pretty=true)' -d  
'{"query": {"prefix": {"name": "u.s"}}}'

# finds (5) but not (4): not ok

curl -s '[http://localhost:9200/test/country/\_search?pretty=true](http://localhost:9200/test/country/_search?pretty=true)' -d  
'{"query": {"prefix": {"name": "u.s."}}}'

Is this expected behavior or a bug?

Thanks,  
George

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 9, 2012, 7:52pm UTC](https://discuss.elastic.co/t/prefix-ending-in-dot/6326/2 "2012-01-09T19:52:19Z")

</div>

prefix query is not analyzed and it expects to find the prefix in a single  
term, use the analyze API to see how the text is broken down. You can use  
the text query in prefix mode for this.

On Mon, Jan 9, 2012 at 4:20 PM, George Sakkis [george.sakkis@gmail.com](mailto:george.sakkis@gmail.com)wrote:

> Hi all,
> 
> it looks like searching for a prefix that ends in a dot does not find  
> documents where a term matches exactly the prefix. Here's an example:
> 
> curl -XDELETE '[http://localhost:9200/test](http://localhost:9200/test)'  
> curl -XPUT '[http://localhost:9200/test/](http://localhost:9200/test/)'
> 
> curl -XPUT '[http://localhost:9200/test/country/1](http://localhost:9200/test/country/1)' -d '{"name": "US of  
> A"}'  
> curl -XPUT '[http://localhost:9200/test/country/2](http://localhost:9200/test/country/2)' -d '{"name": "USA"}'
> 
> curl -XPUT '[http://localhost:9200/test/country/3](http://localhost:9200/test/country/3)' -d '{"name": "U.S of  
> A"}'  
> curl -XPUT '[http://localhost:9200/test/country/4](http://localhost:9200/test/country/4)' -d '{"name": "U.S.  
> of A"}'  
> curl -XPUT '[http://localhost:9200/test/country/5](http://localhost:9200/test/country/5)' -d '{"name":  
> "U.S.A"}'
> 
> curl -XPOST '[http://localhost:9200/test/\_refresh](http://localhost:9200/test/_refresh)'
> 
> # finds (1) and (2): ok
> 
> curl -s '[http://localhost:9200/test/country/\_search?pretty=true](http://localhost:9200/test/country/_search?pretty=true)' -d  
> '{"query": {"prefix": {"name": "us"}}}'
> 
> # finds (3), (4) and (5): ok
> 
> curl -s '[http://localhost:9200/test/country/\_search?pretty=true](http://localhost:9200/test/country/_search?pretty=true)' -d  
> '{"query": {"prefix": {"name": "u.s"}}}'
> 
> # finds (5) but not (4): not ok
> 
> curl -s '[http://localhost:9200/test/country/\_search?pretty=true](http://localhost:9200/test/country/_search?pretty=true)' -d  
> '{"query": {"prefix": {"name": "u.s."}}}'
> 
> Is this expected behavior or a bug?
> 
> Thanks,  
> George

---

<div class="post-metadata">

**Author:** ![George\_Sakkis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/george_sakkis/32/2801_2.png) [@George\_Sakkis](https://discuss.elastic.co/u/George_Sakkis)\
**Post date:** [January 10, 2012, 11:00am UTC](https://discuss.elastic.co/t/prefix-ending-in-dot/6326/3 "2012-01-10T11:00:29Z")

</div>

Ah got it now, the standard analyzer strips of the trailing dot from  
"U.S." which causes the prefix search to fail.

Many thanks!

On Jan 9, 8:52 pm, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> prefix query is not analyzed and it expects to find the prefix in a single  
> term, use the analyze API to see how the text is broken down. You can use  
> the text query in prefix mode for this.
> 
> On Mon, Jan 9, 2012 at 4:20 PM, George Sakkis [george.sak...@gmail.com](mailto:george.sak...@gmail.com)wrote:
> 
> > Hi all,
> 
> > it looks like searching for a prefix that ends in a dot does not find  
> > documents where a term matches exactly the prefix. Here's an example:
> 
> > curl -XDELETE '[http://localhost:9200/test](http://localhost:9200/test)'  
> > curl -XPUT '[http://localhost:9200/test/](http://localhost:9200/test/)'
> 
> > curl -XPUT '[http://localhost:9200/test/country/1'-d](http://localhost:9200/test/country/1'-d) '{"name": "US of  
> > A"}'  
> > curl -XPUT '[http://localhost:9200/test/country/2'-d](http://localhost:9200/test/country/2'-d) '{"name": "USA"}'
> 
> > curl -XPUT '[http://localhost:9200/test/country/3'-d](http://localhost:9200/test/country/3'-d) '{"name": "U.S of  
> > A"}'  
> > curl -XPUT '[http://localhost:9200/test/country/4'-d](http://localhost:9200/test/country/4'-d) '{"name": "U.S.  
> > of A"}'  
> > curl -XPUT '[http://localhost:9200/test/country/5'-d](http://localhost:9200/test/country/5'-d) '{"name":  
> > "U.S.A"}'
> 
> > curl -XPOST '[http://localhost:9200/test/\_refresh](http://localhost:9200/test/_refresh)'
> 
> > # finds (1) and (2): ok
> > 
> > curl -s '[http://localhost:9200/test/country/\_search?pretty=true'-d](http://localhost:9200/test/country/_search?pretty=true'-d)  
> > '{"query": {"prefix": {"name": "us"}}}'
> > 
> > # finds (3), (4) and (5): ok
> > 
> > curl -s '[http://localhost:9200/test/country/\_search?pretty=true'-d](http://localhost:9200/test/country/_search?pretty=true'-d)  
> > '{"query": {"prefix": {"name": "u.s"}}}'
> > 
> > # finds (5) but not (4): not ok
> > 
> > curl -s '[http://localhost:9200/test/country/\_search?pretty=true'-d](http://localhost:9200/test/country/_search?pretty=true'-d)  
> > '{"query": {"prefix": {"name": "u.s."}}}'
> 
> > Is this expected behavior or a bug?
> 
> > Thanks,  
> > George

---

<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, 3:43am UTC](https://discuss.elastic.co/t/prefix-ending-in-dot/6326/4 "2017-07-06T03:43:13Z")

</div>


