Google Suggest

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?

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 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?

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.comwrote:

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 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?

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/
.

-shay.banon

On Thu, Sep 23, 2010 at 3:09 AM, James Cook 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.comwrote:

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.comwrote:

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?

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.comwrote:

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/
.

-shay.banon

On Thu, Sep 23, 2010 at 3:09 AM, James Cook 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

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.comwrote:

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?