# Google Suggest

**URL:** <https://discuss.elastic.co/t/google-suggest/3360>\
**Category:** Elasticsearch\
**Created:** [September 23, 2010, 12:41am UTC](https://discuss.elastic.co/t/google-suggest/3360 "2010-09-23T00:41:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [September 23, 2010, 12:41am UTC](https://discuss.elastic.co/t/google-suggest/3360/1 "2010-09-23T00:41:40Z")

</div>

As the user enters characters into a search field, I want to find the terms  
in my index that contain these characters. I am able to query to find the  
terms, and I have tried several followup filters to try to limit this list  
to those that start with the user entered characters, but no luck yet.

Does anyone know how I might craft this query?

---

<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:** [September 23, 2010, 1:00am UTC](https://discuss.elastic.co/t/google-suggest/3360/2 "2010-09-23T01:00:41Z")

</div>

The way that I would implement a google suggest like capability is a bit  
different. For every search a user enters, I would index it (into a separate  
index) with the total\_hits returned and the user text query (note that the  
user text query can be only part of the actual query executed at the end  
against elasticsearch, also this can be done completely in an async manner).  
For example, index doc that looks like this:

{  
"query" : "the user entered query",  
"hits" : 345829304  
}

Then, to provide the auto suggest, you can search that index, and do prefix  
or more complex query on the "query" field, sorted by the hits or even use  
custom\_score query to get the score (how well it matches the "query"field),  
and the hits into the picture. You can then also display the (expected) hits  
associated with each result.

-shay.banon

On Thu, Sep 23, 2010 at 2:41 AM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:

> As the user enters characters into a search field, I want to find the terms  
> in my index that contain these characters. I am able to query to find the  
> terms, and I have tried several followup filters to try to limit this list  
> to those that start with the user entered characters, but no luck yet.
> 
> Does anyone know how I might craft this query?

---

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [September 23, 2010, 1:09am UTC](https://discuss.elastic.co/t/google-suggest/3360/3 "2010-09-23T01:09:57Z")

</div>

I can see the use of that approach, and I agree that the behavior you  
outline is probably closer to Google Suggest, but I am trying to basically  
generate a set of results analogous to doing a match in a tag cloud. I'm  
able to generate the tag cloud of terms using facets, but I can't figure out  
how to filter the terms for a match against the user text.

For example, I have a lot of articles about animals. If the user type in  
'do', I would like to return the most commonly indexed terms that start with  
'do', such as ['dog', 'doberman', 'donut'].

thanks

On Wed, Sep 22, 2010 at 9:00 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> The way that I would implement a google suggest like capability is a bit  
> different. For every search a user enters, I would index it (into a separate  
> index) with the total\_hits returned and the user text query (note that the  
> user text query can be only part of the actual query executed at the end  
> against elasticsearch, also this can be done completely in an async manner).  
> For example, index doc that looks like this:
> 
> {  
> "query" : "the user entered query",  
> "hits" : 345829304  
> }
> 
> Then, to provide the auto suggest, you can search that index, and do prefix  
> or more complex query on the "query" field, sorted by the hits or even use  
> custom\_score query to get the score (how well it matches the "query"field),  
> and the hits into the picture. You can then also display the (expected) hits  
> associated with each result.
> 
> -shay.banon
> 
> On Thu, Sep 23, 2010 at 2:41 AM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:
> 
> > As the user enters characters into a search field, I want to find the  
> > terms in my index that contain these characters. I am able to query to find  
> > the terms, and I have tried several followup filters to try to limit this  
> > list to those that start with the user entered characters, but no luck yet.
> > 
> > Does anyone know how I might craft this query?

---

<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:** [September 23, 2010, 1:12am UTC](https://discuss.elastic.co/t/google-suggest/3360/4 "2010-09-23T01:12:20Z")

</div>

If you are going to use the terms API, then you can provide a regular  
expression to filter out terms:  
[http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/facets/terms\_facet/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/facets/terms_facet/)  
.

-shay.banon

On Thu, Sep 23, 2010 at 3:09 AM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:

> I can see the use of that approach, and I agree that the behavior you  
> outline is probably closer to Google Suggest, but I am trying to basically  
> generate a set of results analogous to doing a match in a tag cloud. I'm  
> able to generate the tag cloud of terms using facets, but I can't figure out  
> how to filter the terms for a match against the user text.
> 
> For example, I have a lot of articles about animals. If the user type in  
> 'do', I would like to return the most commonly indexed terms that start with  
> 'do', such as ['dog', 'doberman', 'donut'].
> 
> thanks
> 
> On Wed, Sep 22, 2010 at 9:00 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > The way that I would implement a google suggest like capability is a bit  
> > different. For every search a user enters, I would index it (into a separate  
> > index) with the total\_hits returned and the user text query (note that the  
> > user text query can be only part of the actual query executed at the end  
> > against elasticsearch, also this can be done completely in an async manner).  
> > For example, index doc that looks like this:
> > 
> > {  
> > "query" : "the user entered query",  
> > "hits" : 345829304  
> > }
> > 
> > Then, to provide the auto suggest, you can search that index, and do  
> > prefix or more complex query on the "query" field, sorted by the hits or  
> > even use custom\_score query to get the score (how well it matches the  
> > "query"field), and the hits into the picture. You can then also display the  
> > (expected) hits associated with each result.
> > 
> > -shay.banon
> > 
> > On Thu, Sep 23, 2010 at 2:41 AM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com)wrote:
> > 
> > > As the user enters characters into a search field, I want to find the  
> > > terms in my index that contain these characters. I am able to query to find  
> > > the terms, and I have tried several followup filters to try to limit this  
> > > list to those that start with the user entered characters, but no luck yet.
> > > 
> > > Does anyone know how I might craft this query?

---

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [September 23, 2010, 1:19am UTC](https://discuss.elastic.co/t/google-suggest/3360/5 "2010-09-23T01:19:44Z")

</div>

Strange, I read this page a few days ago and don't remember seeing that  
capability. Thanks for the pointer!

On Wed, Sep 22, 2010 at 9:12 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> If you are going to use the terms API, then you can provide a regular  
> expression to filter out terms:  
> [http://www.elasticsearch.com/docs/elasticsearch/rest\_api/search/facets/terms\_facet/](http://www.elasticsearch.com/docs/elasticsearch/rest_api/search/facets/terms_facet/)  
> .
> 
> -shay.banon
> 
> On Thu, Sep 23, 2010 at 3:09 AM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:
> 
> > I can see the use of that approach, and I agree that the behavior you  
> > outline is probably closer to Google Suggest, but I am trying to basically  
> > generate a set of results analogous to doing a match in a tag cloud. I'm  
> > able to generate the tag cloud of terms using facets, but I can't figure out  
> > how to filter the terms for a match against the user text.
> > 
> > For example, I have a lot of articles about animals. If the user type in  
> > 'do', I would like to return the most commonly indexed terms that start with  
> > 'do', such as ['dog', 'doberman', 'donut'].
> > 
> > thanks
> > 
> > On Wed, Sep 22, 2010 at 9:00 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)
> > 
> > > wrote:
> > 
> > > The way that I would implement a google suggest like capability is a bit  
> > > different. For every search a user enters, I would index it (into a separate  
> > > index) with the total\_hits returned and the user text query (note that the  
> > > user text query can be only part of the actual query executed at the end  
> > > against elasticsearch, also this can be done completely in an async manner).  
> > > For example, index doc that looks like this:
> > > 
> > > {  
> > > "query" : "the user entered query",  
> > > "hits" : 345829304  
> > > }
> > > 
> > > Then, to provide the auto suggest, you can search that index, and do  
> > > prefix or more complex query on the "query" field, sorted by the hits or  
> > > even use custom\_score query to get the score (how well it matches the  
> > > "query"field), and the hits into the picture. You can then also display the  
> > > (expected) hits associated with each result.
> > > 
> > > -shay.banon
> > > 
> > > On Thu, Sep 23, 2010 at 2:41 AM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com)wrote:
> > > 
> > > > As the user enters characters into a search field, I want to find the  
> > > > terms in my index that contain these characters. I am able to query to find  
> > > > the terms, and I have tried several followup filters to try to limit this  
> > > > list to those that start with the user entered characters, but no luck yet.
> > > > 
> > > > Does anyone know how I might craft this query?

---

<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, 4:19am UTC](https://discuss.elastic.co/t/google-suggest/3360/6 "2017-07-06T04:19:02Z")

</div>

Closed on July 6, 2017, 4:19am UTC


