# Implementing "search as you type" example

**URL:** https://discuss.elastic.co/t/implementing-search-as-you-type-example/21941
**Category:** Elasticsearch
**Created:** [February 1, 2015, 5:12pm UTC](https://discuss.elastic.co/t/implementing-search-as-you-type-example/21941 "2015-02-01T17:12:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![cching](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cching/32/44800_2.png) [@cching](https://discuss.elastic.co/u/cching)
#### Post date: [February 1, 2015, 5:12pm UTC](https://discuss.elastic.co/t/implementing-search-as-you-type-example/21941/1 "2015-02-01T17:12:54Z")

</div>

Hi,

I'm trying to implement the "search as you type" example  
from [http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/\_index\_time\_search\_as\_you\_type.html](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html)

Can someone see what I'm doing wrong?

curl -XDELETE localhost:9200/my\_index  
echo  
curl -XPUT localhost:9200/my\_index -d '  
{  
"settings": {  
"number\_of\_shards": 1,  
"analysis": {  
"filter": {  
"autocomplete\_filter": {  
"type": "edge\_ngram",  
"min\_gram": 1,  
"max\_gram": 20  
}  
},  
"analyzer": {  
"autocomplete": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": [  
"lowercase",  
"autocomplete\_filter"  
]  
}  
}  
}  
}  
}'  
echo  
curl -XPUT localhost:9200/my\_index/\_mapping/my\_type -d '  
{  
"my\_type": {  
"properties": {  
"name": {  
"type": "string",  
"analyzer": "autocomplete"  
}  
}  
}  
}'  
echo  
curl localhost:9200/my\_index/my\_type/\_bulk -d '  
{ "index": { "\_id": 1 }}  
{ "name": "Brown foxes" }  
{ "index": { "\_id": 2 }}  
{ "name": "Yellow furballs" }  
'  
echo  
curl localhost:9200/my\_index/my\_type/\_search -d '  
{  
"query": {  
"match": {  
"name": "brown fo"  
}  
}  
}'  
echo  
curl localhost:9200/my\_index/my\_type/\_validate/query?explain -d '  
{  
"query": {  
"match": {  
"name": "brown fo"  
}  
}  
}'  
echo  
curl localhost:9200/my\_index/my\_type/\_search -d '  
{  
"query": {  
"match": {  
"name": {  
"query": "brown fo",  
"analyzer": "standard"  
}  
}  
}  
}'  
echo  
curl localhost:9200/my\_index/my\_type/\_validate/query?explain -d '  
{  
"query": {  
"match": {  
"name": {  
"query": "brown fo",  
"analyzer": "standard"  
}  
}  
}  
}'  
echo

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![cching](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cching/32/44800_2.png) [@cching](https://discuss.elastic.co/u/cching)
#### Post date: [February 1, 2015, 5:14pm UTC](https://discuss.elastic.co/t/implementing-search-as-you-type-example/21941/2 "2015-02-01T17:14:21Z")

</div>

Sorry, I should also explain the problem 😉

For both of the searches I'm getting the following:

{"took":1,"timed\_out":false,"\_shards":{"total":1,"successful":1,"failed":0},  
"hits":{"total":0,"max\_score":null,"hits":}}

On Sunday, February 1, 2015 at 11:12:55 AM UTC-6, Craig Ching wrote:

> Hi,
> 
> I'm trying to implement the "search as you type" example from  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html)
> 
> Can someone see what I'm doing wrong?
> 
> curl -XDELETE localhost:9200/my\_index  
> echo  
> curl -XPUT localhost:9200/my\_index -d '  
> {  
> "settings": {  
> "number\_of\_shards": 1,  
> "analysis": {  
> "filter": {  
> "autocomplete\_filter": {  
> "type": "edge\_ngram",  
> "min\_gram": 1,  
> "max\_gram": 20  
> }  
> },  
> "analyzer": {  
> "autocomplete": {  
> "type": "custom",  
> "tokenizer": "standard",  
> "filter": [  
> "lowercase",  
> "autocomplete\_filter"  
> ]  
> }  
> }  
> }  
> }  
> }'  
> echo  
> curl -XPUT localhost:9200/my\_index/\_mapping/my\_type -d '  
> {  
> "my\_type": {  
> "properties": {  
> "name": {  
> "type": "string",  
> "analyzer": "autocomplete"  
> }  
> }  
> }  
> }'  
> echo  
> curl localhost:9200/my\_index/my\_type/\_bulk -d '  
> { "index": { "\_id": 1 }}  
> { "name": "Brown foxes" }  
> { "index": { "\_id": 2 }}  
> { "name": "Yellow furballs" }  
> '  
> echo  
> curl localhost:9200/my\_index/my\_type/\_search -d '  
> {  
> "query": {  
> "match": {  
> "name": "brown fo"  
> }  
> }  
> }'  
> echo  
> curl localhost:9200/my\_index/my\_type/\_validate/query?explain -d '  
> {  
> "query": {  
> "match": {  
> "name": "brown fo"  
> }  
> }  
> }'  
> echo  
> curl localhost:9200/my\_index/my\_type/\_search -d '  
> {  
> "query": {  
> "match": {  
> "name": {  
> "query": "brown fo",  
> "analyzer": "standard"  
> }  
> }  
> }  
> }'  
> echo  
> curl localhost:9200/my\_index/my\_type/\_validate/query?explain -d '  
> {  
> "query": {  
> "match": {  
> "name": {  
> "query": "brown fo",  
> "analyzer": "standard"  
> }  
> }  
> }  
> }'  
> echo

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ce82bc0d-e0a4-485f-bdec-09b93a7456fb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ce82bc0d-e0a4-485f-bdec-09b93a7456fb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)
#### Post date: [February 1, 2015, 5:16pm UTC](https://discuss.elastic.co/t/implementing-search-as-you-type-example/21941/3 "2015-02-01T17:16:35Z")

</div>

For implementing good autocomplete I recommend you look at the completion  
suggester - its much faster and has more capabilities. It was built  
especially for that.

See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/you-complete-me/) and  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html)

You can then complement it with Phrase Suggester to recommend spelling  
corrections etc

edge-grams are less than ideal for this use case given the above tools

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
[Lucene.NET](http://Lucene.NET) committer and PMC member

On Sun, Feb 1, 2015 at 7:12 PM, Craig Ching [craigching@gmail.com](mailto:craigching@gmail.com) wrote:

> Hi,
> 
> I'm trying to implement the "search as you type" example from  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html)
> 
> Can someone see what I'm doing wrong?
> 
> curl -XDELETE localhost:9200/my\_index  
> echo  
> curl -XPUT localhost:9200/my\_index -d '  
> {  
> "settings": {  
> "number\_of\_shards": 1,  
> "analysis": {  
> "filter": {  
> "autocomplete\_filter": {  
> "type": "edge\_ngram",  
> "min\_gram": 1,  
> "max\_gram": 20  
> }  
> },  
> "analyzer": {  
> "autocomplete": {  
> "type": "custom",  
> "tokenizer": "standard",  
> "filter": [  
> "lowercase",  
> "autocomplete\_filter"  
> ]  
> }  
> }  
> }  
> }  
> }'  
> echo  
> curl -XPUT localhost:9200/my\_index/\_mapping/my\_type -d '  
> {  
> "my\_type": {  
> "properties": {  
> "name": {  
> "type": "string",  
> "analyzer": "autocomplete"  
> }  
> }  
> }  
> }'  
> echo  
> curl localhost:9200/my\_index/my\_type/\_bulk -d '  
> { "index": { "\_id": 1 }}  
> { "name": "Brown foxes" }  
> { "index": { "\_id": 2 }}  
> { "name": "Yellow furballs" }  
> '  
> echo  
> curl localhost:9200/my\_index/my\_type/\_search -d '  
> {  
> "query": {  
> "match": {  
> "name": "brown fo"  
> }  
> }  
> }'  
> echo  
> curl localhost:9200/my\_index/my\_type/\_validate/query?explain -d '  
> {  
> "query": {  
> "match": {  
> "name": "brown fo"  
> }  
> }  
> }'  
> echo  
> curl localhost:9200/my\_index/my\_type/\_search -d '  
> {  
> "query": {  
> "match": {  
> "name": {  
> "query": "brown fo",  
> "analyzer": "standard"  
> }  
> }  
> }  
> }'  
> echo  
> curl localhost:9200/my\_index/my\_type/\_validate/query?explain -d '  
> {  
> "query": {  
> "match": {  
> "name": {  
> "query": "brown fo",  
> "analyzer": "standard"  
> }  
> }  
> }  
> }'  
> echo
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZvjP1CsF9JSs1H0u6fioT\_igm%3DBMxWfYs3iY2A5M6SXJw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZvjP1CsF9JSs1H0u6fioT_igm%3DBMxWfYs3iY2A5M6SXJw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![cching](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cching/32/44800_2.png) [@cching](https://discuss.elastic.co/u/cching)
#### Post date: [February 1, 2015, 5:20pm UTC](https://discuss.elastic.co/t/implementing-search-as-you-type-example/21941/4 "2015-02-01T17:20:42Z")

</div>

That's fine, but I still want to know what I'm doing wrong in my example  
(taken pretty much verbatim from the link provided).

That said, I am planning on evaluating both for my use case. The problem I  
have with the suggester is the duplication. That said, I'd rather not  
debate that right now as I've not even really looked into it yet 😉

On Sunday, February 1, 2015 at 11:16:42 AM UTC-6, Itamar Syn-Hershko wrote:

> For implementing good autocomplete I recommend you look at the completion  
> suggester - its much faster and has more capabilities. It was built  
> especially for that.
> 
> See [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/blog/you-complete-me/) and  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html)
> 
> You can then complement it with Phrase Suggester to recommend spelling  
> corrections etc
> 
> edge-grams are less than ideal for this use case given the above tools
> 
> --
> 
> Itamar Syn-Hershko  
> [http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
> Freelance Developer & Consultant  
> [Lucene.NET](http://Lucene.NET) committer and PMC member
> 
> On Sun, Feb 1, 2015 at 7:12 PM, Craig Ching \<[craig...@gmail.com](mailto:craig...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi,
> > 
> > I'm trying to implement the "search as you type" example from  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html)
> > 
> > Can someone see what I'm doing wrong?
> > 
> > curl -XDELETE localhost:9200/my\_index  
> > echo  
> > curl -XPUT localhost:9200/my\_index -d '  
> > {  
> > "settings": {  
> > "number\_of\_shards": 1,  
> > "analysis": {  
> > "filter": {  
> > "autocomplete\_filter": {  
> > "type": "edge\_ngram",  
> > "min\_gram": 1,  
> > "max\_gram": 20  
> > }  
> > },  
> > "analyzer": {  
> > "autocomplete": {  
> > "type": "custom",  
> > "tokenizer": "standard",  
> > "filter": [  
> > "lowercase",  
> > "autocomplete\_filter"  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }'  
> > echo  
> > curl -XPUT localhost:9200/my\_index/\_mapping/my\_type -d '  
> > {  
> > "my\_type": {  
> > "properties": {  
> > "name": {  
> > "type": "string",  
> > "analyzer": "autocomplete"  
> > }  
> > }  
> > }  
> > }'  
> > echo  
> > curl localhost:9200/my\_index/my\_type/\_bulk -d '  
> > { "index": { "\_id": 1 }}  
> > { "name": "Brown foxes" }  
> > { "index": { "\_id": 2 }}  
> > { "name": "Yellow furballs" }  
> > '  
> > echo  
> > curl localhost:9200/my\_index/my\_type/\_search -d '  
> > {  
> > "query": {  
> > "match": {  
> > "name": "brown fo"  
> > }  
> > }  
> > }'  
> > echo  
> > curl localhost:9200/my\_index/my\_type/\_validate/query?explain -d '  
> > {  
> > "query": {  
> > "match": {  
> > "name": "brown fo"  
> > }  
> > }  
> > }'  
> > echo  
> > curl localhost:9200/my\_index/my\_type/\_search -d '  
> > {  
> > "query": {  
> > "match": {  
> > "name": {  
> > "query": "brown fo",  
> > "analyzer": "standard"  
> > }  
> > }  
> > }  
> > }'  
> > echo  
> > curl localhost:9200/my\_index/my\_type/\_validate/query?explain -d '  
> > {  
> > "query": {  
> > "match": {  
> > "name": {  
> > "query": "brown fo",  
> > "analyzer": "standard"  
> > }  
> > }  
> > }  
> > }'  
> > echo
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3265ddb0-eab4-4cc7-9fc0-66ae56c358e5%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/f6f5aa6e-a7f1-4d43-af08-95a16bfa9f1a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f6f5aa6e-a7f1-4d43-af08-95a16bfa9f1a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:35am UTC](https://discuss.elastic.co/t/implementing-search-as-you-type-example/21941/5 "2017-07-06T00:35:27Z")

</div>


