

# Querying Your Search Domain for More Information in Amazon CloudSearch
<a name="querying-for-more-info"></a>

When you submit a search request, Amazon CloudSearch returns a collection of the documents that match your search criteria. You can also retrieve:
+ The contents of selected fields
+ Facet information that enables you to categorize the results
+ Statistics for the values contained in numeric fields
+ Highlights that show the search hits in the field data
+ Autocomplete suggestions

**Topics**
+ [Retrieve field values](retrieving-data.md)
+ [Getting Statistics for Numeric Fields in Amazon CloudSearch](retrieving-stats.md)
+ [Getting and Using Facet Information in Amazon CloudSearch](faceting.md)
+ [Highlighting Search Hits in Amazon CloudSearch](highlighting.md)
+ [Getting Autocomplete Suggestions in Amazon CloudSearch](getting-suggestions.md)

# Retrieving Data from Index Fields in Amazon CloudSearch
<a name="retrieving-data"></a>

By default, the search results include all return enabled fields. To return a subset of the return enabled fields or return expression values for the matching documents, you can specify the `return` parameter. To return only the document IDs for the matching documents, specify `return=_no_fields`. To retrieve the relevance score calculated for each document, specify `return=_score`. You specify multiple return fields as a comma separated list. For example, `return=title,_score` returns just the title and relevance score of each matching document.

Only fields configured to be return enabled can be included in the search results. Making fields return enabled increases the size of your index, which can increase the cost of running your domain. You should only store document data in the search index by making fields return enabled when it's difficult or costly to retrieve the data using other means. Because it can take some time to apply document updates across the domain, you should retrieve critical data such as pricing information by using the returned document IDs instead of returned from the index.

For example, to include the *title* and relevance *\$1score* in the search results, specify the following:

```
search?q=star -wars&return=title,_score&size=3
```

The specified fields are included with each hit in the search results:

```
{
  "status" : {
    "rid" : "y9Dzhs8oEwqMHnk=",
    "time-ms" : 2
  },
  "hits" : {
    "found" : 76,
    "start" : 0,
    "hit" : [ {
      "id" : "tt1411664",
      "fields" : {
        "title" : "Bucky Larson: Born to Be a Star",
        "_score" : "9.231539"
      }
    }, {
      "id" : "tt1911658",
      "fields" : {
        "title" : "The Penguins of Madagascar",
        "_score" : "7.1051397"
      }
    }, {
      "id" : "tt0120601",
      "fields" : {
        "title" : "Being John Malkovich",
        "_score" : "6.206055"
      }
    } ]
  }
}
```

# Getting Statistics for Numeric Fields in Amazon CloudSearch
<a name="retrieving-stats"></a>

Amazon CloudSearch can return the following statistics for facet-enabled numeric fields:
+ `count`–The number of documents that contain a value in the specified field.
+ `max`–The maximum value found in the specified field.
+ `mean`–The average of the values found in the specified field.
+ `min`–The minimum value found in the specified field.
+ `missing`–The number of documents that do not contain a value in the specified field.
+ `stddev`–A measure to quantify the amount of deviation, or variation, in the field values. A low standard deviation indicates that the values across all documents are close to the mean. A high standard deviation indicates that the values are spread out over a large range. The standard deviation is calculated by taking the square root of the variance, which is the average of the squared differences from the mean. 
+ `sum`–The sum of the field values across all documents.
+ `sumOfSquares`–The sum of all field values squared.

To get statistics for a field you use the `stats.FIELD` parameter. `FIELD` is the name of a facet-enabled numeric field. You specify an empty JSON object, `stats.FIELD={}`, to get all of the available statistics for the specified field. (The `stats.FIELD` parameter does not support any options; you must pass an empty JSON object.) You can request statistics for multiple fields in the same request.

You can get statistics only for facet-enabled numeric fields: `date`, `date-array`, `double`, `double-array`, `int`, or `int-array`. Note that only the `count`, `max`, `min`, and `missing` statistics are returned for `date` and `date-array` fields. For more information about enabling a field to return facets, see [Configuring Index Fields](configuring-index-fields.md).

For example, to search for *star* and get statistics for the *year* field, specify the following:

```
search?q=star&stats.year={}
```

# Getting and Using Facet Information in Amazon CloudSearch
<a name="faceting"></a>

**Topics**
+ [Getting Facet Information in Amazon CloudSearch](#getting-facet-info)
+ [Using Facet Information in Amazon CloudSearch](#using-facet-info)

A *facet* is an index field that represents a category that you want to use to refine and filter search results. When you submit search requests to Amazon CloudSearch, you can request facet information to find out how many documents share the same value in a particular field. You can display this information along with the search results, and use it to enable users to interactively refine their searches. (This is often referred to as faceted navigation or faceted search.)

You can get facet information for any facet-enabled field by specifying the `facet.FIELD` parameter in your search request. By default, Amazon CloudSearch returns facet counts for the top 10 values. For more information about enabling a field to return facets, see [Configuring Index Fields](configuring-index-fields.md). For a description of the `facet.FIELD` parameter, see [Search Request Parameters](search-api.md#search-request-parameters) in the Search API reference.

You can specify facet options to control the sorting of the facet values for each field, limit the number of facet values returned, or choose what facet values to count and return. 

## Getting Facet Information in Amazon CloudSearch
<a name="getting-facet-info"></a>

To get facet information for a field, you use the `facet.FIELD` parameter. `FIELD` is the name of a facet-enabled field. You specify facet options as a JSON object. If the JSON object is empty (`facet.FIELD={}`), facet counts are computed for all field values, the facets are sorted by facet count, and the top 10 facets are returned in the results. You can request facet information for multiple fields in the same request.

You can retrieve facet information in two ways:
+ `sort`—Returns facet information sorted either by facet counts or facet values.
+ `buckets`—Returns facet information for particular facet values or ranges.

### Sorting Facet Information
<a name="sorting-facets"></a>

You specify the `sort` option to control how the facet information is sorted. There are two sort options: `count` and `bucket`: 
+ Use `count` to sort the facets by facet counts. For example, `facet.year={sort:'count'}` counts the number of matches that have the same year value and sorts the facet information by that number. 
+ Use `bucket` to sort the facets by the facet values. For example, `facet.year={sort:'bucket'}` . 

When you use the `sort` option, you can specify the `size` option to control the maximum number of facet values returned in the results. The `size` option is valid only when you use the `sort` option.

In the following example, facet information is calculated for the `genres` field, the genres are sorted by facet value, and the first 5 genres are returned in the results:

```
facet.genres={sort:'bucket', size:5}
```

### Bucketing Facet Information
<a name="bucketing-facets"></a>

You can explicitly specify the facet values or ranges that you want to count by using the `buckets` option. Buckets are specified as an array of values or ranges, for example, `facet.color={buckets:["red","green","blue"]}`. 

 To specify a range of values, use a comma (,) to separate the upper and lower bounds and enclose the range using brackets or braces. A square bracket, [ or ], indicates that the bound is included in the range, a curly brace, \$1 or \$1, excludes the bound. You can omit the upper or lower bound to specify an open-ended range. When omitting a bound, you must use a curly brace. For example, `facet.year={buckets:["[1970,1979]","[1980,1989]", "[1990,1999]","[2000,2009]","[2010,}"]}`. For a timestamp, you can use `q=-poet&facet.release_date={buckets:["[\'1980-01-01T00:00:00Z\',\'1986-01-01T00:00:01Z\']"]}`.

The `sort` and `size` options are not valid if you specify buckets.

Amazon CloudSearch supports two methods for calculating bucket counts, `filter` and `interval`. By default, the `filter` method is used, which simply submits an additional filter query for each bucket to get the bucket counts. While this works well in many cases, if you have a high update rate or are retrieving a large number of facets, performance can suffer because those queries can't take advantage of the internal caching mechanism. 

 If you're experiencing slow query performance for bucketed facets, try setting the buckets method to `interval`, which post-processes the result set rather than submitting multiple queries:

```
facet.year={buckets:["[1970,1979]","[1980,1989]","[1990,1999]"],method:"interval"}
```

We recommend doing your own performance testing to determine which method is best for your application. In general, the `filter` method is faster if you have a fairly low update rate and aren't retrieving a large number of buckets. However, if you have a high update rate or a lot of buckets, using the `interval` method to post-process the result set can result in significantly faster query performance.

## Using Facet Information in Amazon CloudSearch
<a name="using-facet-info"></a>

You can display facet information to enable users to more easily browse search results and identify the information they are interested in. For example, if a user is trying to find one of the Star Trek movies, but can't remember the full title, he might start by searching for *star*. If you want to display top facets for *genre*, you would include `facet.FIELD` in the query, along with the number of facet values that you want to retrieve for each facet:

```
search?q=star&facet.genres={sort:'count',size:5}&format=xml&return=_no_fields
```

The preceding example gives you the following information in the search response:

```
<results>
    <status rid="v7r9hs8oFQqMHnk=" time-ms="3"/>
    <hits found="85" start="0">
        <hit id="tt1411664"/>
        <hit id="tt1911658"/>
        <hit id="tt0086190"/>
        <hit id="tt0120601"/>
        <hit id="tt2141761"/>
        <hit id="tt1674771"/>
        <hit id="tt0056687"/>
        <hit id="tt0397892"/>
        <hit id="tt0258153"/>
        <hit id="tt0796366"/>
    </hits>
    <facets>
        <facet name="genres">
            <bucket value="Comedy" count="41"/><bucket value="Drama" count="35"/>
            <bucket value="Adventure" count="29"/>
            <bucket value="Sci-Fi" count="24"/>
            <bucket value="Action" count="20"/>
        </facet>
    </facets>
</results>
```

### Multi-Select Facets in Amazon CloudSearch
<a name="multi-select-facets"></a>

If you want to display the available facets and enable users to select multiple values to refine the results, you can submit one request to get the documents that match the facet constraints and additional requests to get the facet counts. 

For example, in the sample movie data, the `genres`, `rating`, and `year` fields are facet enabled. If the user searches for the term *poet*, you can submit the following request to get the matching movies and the facet counts for the `genres`, `rating`, and `year` fields:

```
q=poet&facet.genres={}&facet.rating={}&facet.year={}&return=_no_fields
```

Because no `facet.FIELD` options are specified, Amazon CloudSearch counts all of the facet values and returns the top 10 values for each facet:

```
{
  "status" : {
    "rid" : "it3T8tIoDgrUSvA=",
    "time-ms" : 5
  },
  "hits" : {
    "found" : 14,
    "start" : 0,
    "hit" : [ 
       {"id" : "tt0097165"}, 
       {"id" : "tt0059113"}, 
       { "id" : "tt0108174"}, 
       {"id" : "tt1067765"}, 
       { "id" : "tt1311071"}, 
       {"id" : "tt0810784"}, 
       {"id" : "tt0819714"}, 
       {"id" : "tt0203009"}, 
       {"id" : "tt0114702"}, 
       {"id" : "tt0107840"} ]
  },
  "facets" : {
    "genres" : {
      "buckets" : [ 
         {"value" : "Drama","count" : 12}, 
         {"value" : "Romance","count" : 9}, 
         {"value" : "Biography", "count" : 4}, 
         {"value" : "Comedy","count" : 2}, 
         {"value" : "Thriller","count" : 2}, 
         {"value" : "War","count" : 2}, 
         {"value" : "Crime","count" : 1}, 
         {"value" : "History","count" : 1}, 
         {"value" : "Musical","count" : 1} ]
    },
    "rating" : {
      "buckets" : [ 
         {"value" : "6.3","count" : 3}, 
         {"value" : "6.2","count" : 2}, 
         {"value" : "7.1","count" : 2}, 
         {"value" : "7.9","count" : 2}, 
         {"value" : "5.3","count" : 1}, 
         {"value" : "6.1""count" : 1}, 
         {"value" : "6.4","count" : 1}, 
         {"value" : "6.9","count" : 1}, 
         {"value" : "7.6","count" : 1} ]
    },
    "year" : {
      "buckets" : [ 
         {"value" : "2013","count" : 3}, 
         {"value" : "1993","count" : 2}, 
         {"value" : "1965","count" : 1}, 
         {"value" : "1989","count" : 1}, 
         {"value" : "1995","count" : 1}, 
         {"value" : "2001","count" : 1}, 
         {"value" : "2004","count" : 1}, 
         {"value" : "2006","count" : 1}, 
         {"value" : "2008","count" : 1}, 
         {"value" : "2009","count" : 1} ]
    }
  }
}
```

When the user refines the search by selecting facet values, you use those facet selections to filter the results. For example, if the user selects *2013*, *2012*, and *1993*, the following request gets the matching movies released during those years:

```
q=poet&fq=(or year:2013 year:2012 year:1993)&facet.genres={}&facet.rating={}
&facet.year={}&return=_no_fields
```

This gets the documents that match the user's selection and the facet counts with the filter applied:

```
{
  "status" : {
    "rid" : "zMP38tIoDwrUSvA=",
    "time-ms" : 6
  },
  "hits" : {
    "found" : 6,
    "start" : 0,
    "hit" : [ 
       {"id" : "tt0108174"}, 
       {"id" : "tt1067765"}, 
       {"id" : "tt1311071"}, 
       {"id" : "tt0107840"}, 
       {"id" : "tt1462411"}, 
       {"id" : "tt0455323"} ]
  },
  "facets" : {
    "genres" : {
      "buckets" : [ 
         {"value" : "Drama","count" : 4}, 
         {"value" : "Romance","count" : 3}, 
         {"value" : "Comedy","count" : 2}, 
         {"value" : "Thriller","count" : 2}, 
         {"value" : "Biography","count" : 1}, 
         {"value" : "Crime","count" : 1} ]
    },
    "rating" : {
      "buckets" : [ 
         {"value" : "6.3","count" : 2}, 
         {"value" : "5.3","count" : 1}, 
         {"value" : "6.2","count" : 1}, 
         {"value" : "6.4","count" : 1}, 
         {"value" : "7.1","count" : 1} ]
    },
    "year" : {
      "buckets" : [ 
         {"value" : "2013","count" : 3}, 
         {"value" : "1993","count" : 2}, 
         {"value" : "2012","count" : 1} ]
    }
  }
}
```

This is what you want to show for the genres and ratings. However, to enable the user to change the year filter, you need to get the facet counts for the years that *aren't* selected. To do this, you submit a second request to retrieve the facet counts for the year field without the filter:

```
q=poet&facet.year={}&size=0
```

There's no need to retrieve the matching documents, so the `size` parameter is set to zero to minimize the request latency. The request returns just the facet information for the `year` field:

```
{
  "status" : {
    "rid" : "x/7r0NIoRwqlHfo=",
    "time-ms" : 4
  },
  "hits" : {
    "found" : 14,
    "start" : 0,
    "hit" : [ ]
  },
  "facets" : {
    "year" : {
      "buckets" : [ 
         {"value" : "2013","count" : 3}, 
         {"value" : "1993","count" : 2}, 
         {"value" : "1965","count" : 1}, 
         {"value" : "1989","count" : 1}, 
         {"value" : "1995","count" : 1}, 
         {"value" : "2001","count" : 1}, 
         {"value" : "2004","count" : 1}, 
         {"value" : "2006","count" : 1}, 
         {"value" : "2008","count" : 1}, 
         {"value" : "2009","count" : 1} ]
    }
  }
}
```

To minimize the response time, you can send this request in parallel with the request to get the filtered results. However, keep in mind that these additional requests can impact your overall query performance, and it might be necessary to scale your domain up to handle the additional traffic. (For more information about scaling, see [Configuring Scaling Options in Amazon CloudSearch](configuring-scaling-options.md).)

If the user further refines the search by selecting a genre or rating, you add that to the filter criteria to get the matching documents. For example, the following request gets the movies released in 2013, 2012, or 1993 that have a rating of 6.3:

```
q=poet&fq=(and rating:6.3 (or year:2013 year:2012 year:1993))&facet.genres={}&return=_no_fields
```

Getting the facet information for genres in this request returns the facet counts with the rating and year filters applied:

```
{
  "status" : {
    "rid" : "l66b89IoEArUSvA=",
    "time-ms" : 6
  },
  "hits" : {
    "found" : 2,
    "start" : 0,
    "hit" : [ 
       {"id" : "tt1462411"}, 
       {"id" : "tt0455323"} ]
  },
  "facets" : {
    "genres" : {
      "buckets" : [ 
         {"value" : "Drama","count" : 2} ]
    }
  }
}
```

To enable the user to select a different rating, you submit an additional request to get the rating facet counts with only the year filter applied: 

```
q=poet&fq=(or year:2013 year:2012 year:1993)&facet.rating={}&size=0
```

This request gets the following response:

```
{
  "status" : {
    "rid" : "jqWj89IoEQrUSvA=",
    "time-ms" : 5
  },
  "hits" : {
    "found" : 6,
    "start" : 0,
    "hit" : [ ]
  },
  "facets" : {
    "rating" : {
      "buckets" : [ 
         {"value" : "6.3","count" : 2}, 
         {"value" : "5.3","count" : 1}, 
         {"value" : "6.2","count" : 1}, 
         {"value" : "6.4","count" : 1}, 
         {"value" : "7.1","count" : 1} ]
    }
  }
}
```

Similarly, you need another request to get the year facet counts with only the rating filter applied:

```
q=poet&fq=rating:6.3&facet.year={}&size=0
```

This request gets the following response:

```
{
  "status" : {
    "rid" : "4L6F8NIoDQrUSvA=",
    "time-ms" : 4
  },
  "hits" : {
    "found" : 3,
    "start" : 0,
    "hit" : [ ]
  },
  "facets" : {
    "year" : {
      "buckets" : [ 
         {"value" : "1995","count" : 1}, 
         {"value" : "2012","count" : 1}, 
         {"value" : "2013","count" : 1} ]
    }
  }
}
```

# Highlighting Search Hits in Amazon CloudSearch
<a name="highlighting"></a>

Amazon CloudSearch can return excerpts with the search results to show where the search terms occur within a particular field of a matching document. For example, in the following excerpt the search terms *luke skywalker* are highlighted within the `plot` field:

```
highlights": {
    "plot": "After the rebels have been brutally overpowered by the Empire on
    their newly established base, *Luke* *Skywalker* takes advanced Jedi 
    training with Master Yoda, while his friends are pursued by Darth Vader 
    as part of his plan to capture *Luke*."
}
```

If you search for a phrase, the matching documents must contain that phrase. However, when you retrieve highlights, the terms in the phrase are highlighted individually. If you search for the phrase `"Luke Skywalker"` and retrieve highlights for the `plot` field as shown in the previous example, the term `Luke` is highlighted even when it isn't followed by `Skywalker`. Highlights are returned for the first 10 KB of data in a field. If the field contains more than 10 KB of data and the search terms appear past the 10 KB limit, they are not highlighted.

You can get highlights for any highlight enabled field by specifying the `highlight.FIELD` parameter in your search request. For example, to get highlights for the `plot` field shown, you could specify the following:

```
search?q=star wars&highlight.plot={}
```

For more information about enabling a field to return highlights, see [Configuring Index Fields](configuring-index-fields.md).

You can control how many occurrences of the search term(s) within an excerpt are highlighted, how they should be highlighted, and whether the excerpt is returned as plain text or HTML. When Amazon CloudSearch returns excerpts as HTML, non-alphanumeric characters are escaped with HTML entity encoding. This is done to minimize the risks associated with embedding untrusted HTML content, since the field might have originally been populated with user-generated content. 

You specify highlight options as a JSON object. If the JSON object is empty, `highlight.FIELD={}`, Amazon CloudSearch highlights all occurrences of the search term(s) by enclosing them in HTML emphasis tags, <em>*term*</em>, and the excerpts are returned as HTML. 
+ To specify whether the excerpt should be returned as `text` or `html`, use the `format` option; for example, `highlight.plot={format:'text'}`.
+ To specify the maximum number of occurrences of the search term(s) you want to highlight, use the `max_phrases` option; for example, `highlight.plot={max_phrases:3}`. The default is 1, the maximum is 5.
+ To specify the string to prepend to each highlighted term, use the `pre_tag` option; for example, `highlight.plot={pre_tag:'<strong>', post_tag:'</strong>'}`.
+ To specify the string to append to each highlighted term, use the `post_tag` option; for example, `highlight.plot={pre_tag:'<strong>', post_tag:'</strong>'}`.

# Getting Autocomplete Suggestions in Amazon CloudSearch
<a name="getting-suggestions"></a>

This section describes how to configure suggesters so you can retrieve suggestions. Suggestions are possible matches for an incomplete search query—they enable you to display likely matches before users finish typing their queries. In Amazon CloudSearch, suggestions are based on the contents of a particular text field. When you request suggestions, Amazon CloudSearch finds all of the documents whose values in the suggester field start with the specified query string—the beginning of the field must match the query string to be considered a match. The return data includes the field value and document ID for each match. You can configure suggesters to find matches for the exact query string, or to perform approximate string matching (fuzzy matching) to correct for typographical errors and misspellings. 

For more information about the suggest API, see [Suggest](search-api.md#suggest) in the [Search API Reference](search-api.md).

**Topics**
+ [Configuring Suggesters for Amazon CloudSearch](#configuring-suggesters)
+ [Retrieving Suggestions in Amazon CloudSearch](#retrieving-suggestions)

## Configuring Suggesters for Amazon CloudSearch
<a name="configuring-suggesters"></a>

When you configure a suggester, you must specify the name of the text field you want to search for possible matches and a unique name for the suggester. Fields used for suggestions must be return enabled. Only the first 512 bytes of data in the field are used to generate suggestions. 

Suggester names must begin with a letter and be at least three and no more than 64 characters long. The allowed characters are: a-z (lower-case letters), 0-9, and \$1 (underscore). The suggester name is specified in the query string when you retrieve suggestions, so it's best to use short names. The name *score* is reserved and cannot be used as a suggester name. 

Suggesters also support two options:
+ `FuzzyMatching`—You can set the level of fuzziness allowed when suggesting matches for a string to none, low, or high. With none, the specified string is treated as an exact prefix. With low, suggestions must differ from the specified string by no more than one character. With high, suggestions can differ by up to two characters. The default is none. 
+ `SortExpression`—You can configure this expression to compute a score for each suggestion to control how they are sorted. The scores are rounded to the nearest integer, with a floor of 0 and a ceiling of 2^31-1. A document's relevance score is not computed for suggestions, so sort expressions cannot reference the `_score` value. To sort suggestions using a numeric field or existing expression, simply specify the name of the field or expression. If no expression is configured for the suggester, the suggestions are sorted in alphabetical order. Note that an expression defined within a suggester cannot be referenced in search requests or other expressions. If want to use an expression for other purposes, add it to your domain configuration and reference it by name from the suggester. For more information about expressions, see [Configuring Expressions](configuring-expressions.md).

If you want to get suggestions from multiple text fields, you define a suggester for each field and submit separate suggestion requests to get matches from each suggester. You can configure up to ten suggesters. Suggesters can consume significant amounts of memory and disk space, particularly if you use text-heavy source fields and set fuzzy matching to high.

**Tip**  
Instead of configuring suggesters to use *all* possibilities from *all* documents, consider indexing the most popular 1,000 or 10,000 search queries and configuring suggesters to use those. You can store the queries in a separate Amazon CloudSearch index or in a field used only for suggestions.

The easiest way to define suggesters is through the [**Suggesters** page](#configuring-suggesters-console) in the Amazon CloudSearch console. You can also define suggesters using the AWS SDKs or AWS CLI.

**Important**  
After you add a suggester to your search domain, you must run indexing before you can use it to retrieve suggestions. As you add and delete documents, you must periodically rebuild your index to update the suggestions. Suggestions won't reflect added or deleted documents until you call `IndexDocuments`. 

### Configuring Suggesters through the Amazon CloudSearch Console
<a name="configuring-suggesters-console"></a>

You can easily add, update, and delete suggesters through the Amazon CloudSearch console. 

**To add a suggester**

1. Open the Amazon CloudSearch console at [https://console.aws.amazon.com/cloudsearch/home](https://console.aws.amazon.com/cloudsearch/home).

1. In the left navigation pane, choose **Domains**. 

1. Choose the name of the domain to open its configuration.

1. Go to the **Advanced search options** tab.

1. In the **Suggesters** pane, choose **Add suggester**.s

1. Enter a name for the new suggester.

1. For **Source field**, specify the text field to use for suggestions.

1. To include suggestions that correct for minor misspellings or typos, set **Fuzzy matching** to **Low** or **High**. When set to low, the suggestions include terms that differ from the user query string by a single character. When set to high, the suggestions include terms that differ by up to two characters. 

1. To control how the suggestions are sorted, enter a numeric expression in the **Sort expression** field. The expression can simply be the name of the numeric field you want to use to sort the suggestions, the name of an existing expression, or any valid expression. For more information about expressions, see [Configuring Expressions](configuring-expressions.md). 

1. Click **Save changes**.

1. When you're done configuring suggesters for your search domain, you must re-index your domain before you can use the suggesters. To run indexing, go to the domain dashboard and choose **Actions**, **Run indexing**.

### Configuring Suggesters with the AWS CLI
<a name="configuring-suggesters-clt"></a>

You can add or update suggesters with the `aws cloudsearch define-suggester` command. To remove a suggester, you use `aws cloudsearch delete-suggester`.

**To add or update a suggester**
+ Run the `aws cloudsearch define-suggester` command. You specify the configuration of the suggester in JSON with the `--suggester` option. The suggester configuration must be enclosed in quotes and all quotes within the configuration must be escaped with a backslash. For the format of the suggester configuration, see [define-suggester](https://docs.aws.amazon.com/cli/latest/reference/cloudsearch/define-suggester.html) in the AWS CLI Command Reference. For example, the following command configures a suggester called `mysuggester` to return suggestions based on the `title` field.

  ```
  aws cloudsearch define-suggester --domain-name movies --suggester "{\"SuggesterName\": \"mysuggester\", \"DocumentSuggesterOptions\": {\"SourceField\":\"title\"}}" 
  {
    "Suggester": {
      "Status": {
        "PendingDeletion": false,
        "State": "RequiresIndexDocuments",
        "CreationDate": "2014-06-26T17:26:43Z",
        "UpdateVersion": 27,
        "UpdateDate": "2014-06-26T17:26:43Z"
      },
      "Options": {
        "DocumentSuggesterOptions": {
          "SourceField": "title"
        },
        "SuggesterName": "mysuggester"
      }
    }
  }
  ```

  You can use the `--fuzzy-matching` option to include suggestions that correct for minor misspellings or typos. Valid values for fuzzy matching are `none`, `low`, and `high`. (The default is `none`.) When set to `low`, the suggestions will include terms that differ from the user query string by a single character. When set to `high`, the suggestions will include terms that differ by up to two characters. For example, the following command configures `mysuggester` to include suggestions that differ from the user query string by just one character: 

  ```
  aws cloudsearch  --name mysuggester --source title 
    --fuzzy-matching low
  ```

  You can use the `--sort-expression` option to control how the returned suggestions are sorted. You can use any valid expression for sorting. (Often, this will just be the name of a numeric field or a predefined expression.) For example, to sort the suggestions returned by `mysuggester` according to the value in the `year` field, specify:

  ```
  aws cloudsearch define-suggester --name mysuggester --source title 
    --fuzzy-matching low --sort-expression year
  ```

**To delete a suggester**
+ Run the `aws cloudsearch delete-suggester` command and specify the `--name` option. For example, to delete `mysuggester`:

  ```
  aws cloudsearch delete-suggester --name mysuggester --delete
  ```

### Configuring Suggesters Using the AWS SDKs
<a name="configuring-suggesters-sdk"></a>

The AWS SDKs (except the Android and iOS SDKs) support all of the Amazon CloudSearch actions defined in the Amazon CloudSearch Configuration API, including `DefineSuggester`. For more information about installing and using the AWS SDKs, see [AWS Software Development Kits](http://aws.amazon.com/code).

## Retrieving Suggestions in Amazon CloudSearch
<a name="retrieving-suggestions"></a>

You retrieve suggestions by sending requests to the `suggest` resource on a domain's search endpoint via HTTP GET. For example:

```
http://search-movies-rr2f34ofg56xneuemujamut52i.us-east-1.cloudsearch.
amazonaws.com/2013-01-01/suggest?q=oce&suggester=mysuggester
```

You must specify the API version in the request and the query string must be URL-encoded. The maximum size of a suggestion request is 8190 bytes, including the HTTP method, URI, and protocol version.

 The `suggest` resource supports four parameters:
+ `q`—The string that you want to get suggestions for. 
+ `suggester`—The name of the suggester you want to use.
+ `size`—The number of suggestions to retrieve. By default, the top ten suggestions are returned. (The suggestions are sorted according the sort expression defined in the suggester. If no sort expression is defined in the suggester, the suggestions are sorted in alphabetical order.)
+ `format`—The content type of the response, `json` or `xml`. By default, suggestions are returned in JSON.

The `q` and `suggester` parameters must be specified. No suggestions are returned if you request suggestions for an empty string. The `size` and `format` parameters are optional. 

The following example gets suggestions for the string `oce` based on the contents of the `title` field.

```
http://search-imdb2-m2brrr7ex7z6sqhgwsjdmcuvd4.us-east-1.cloudsearch.amazonaws.com/2013-01-01/suggest?q=oce&suggester=title
{
  "status": {
    "rid": "646f5s0oDAr8pVk=",
    "time-ms": 2
  },
  "suggest": {
    "query": "oce",
    "found": 3,
    "suggestions": [{
        "suggestion": "Ocean's Eleven",
        "score": 0,
        "id": "tt0054135"
      },
      {
        "suggestion": "Ocean's Thirteen",
        "score": 0,
        "id": "tt0496806"
      },
      {
        "suggestion": "Ocean's Twelve",
        "score": 0,
        "id": "tt0349903"
      }
    ]
  }
}
```