Amazon CloudSearch
Developer Guide (API Version 2011-02-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Getting Facet Information for Particular Values in Amazon CloudSearch

The facet-FIELD-constraints parameter controls which facet values are returned for the specified facet. You specify the facet values you want to count as a comma-separated list. The values must be enclosed within single quotes. Note that the facet values are case sensitive: facet-genre-constraints='drama' is not the same as facet-genre-constraints='Drama'.

Note

If commas occur in a facet value you want to use as a constraint, the comma must be escaped with a backslash. For example, facet-actor-constraints='Bai\, Ling','Bryant\, Gene'.

For example, to find out how many documents have Drama or Sci-Fi in the genre field, you'd set facet-genre-constraints='Drama','Sci-Fi':

search?q=star&facet=genre&facet-genre-constraints='Drama','Sci-Fi'

In the response, the counts are only shown for the specified constraints:

facets":{"genre":
    {"constraints":[
        {"value":"Sci-Fi","count":20},
        {"value":"Drama","count":4}
    ]}
}

The facet-FIELD-constraints parameter can also be used with uint fields. You can specify individual values, as well as ranges of values, which enables you to do range-based binning. You can use the min and max values returned when you don't specify any constraints to calculate the ranges, and then get facet counts for each of those ranges with a subsequent search.

The values and ranges are specified as a comma-separated list. For example, the following request gets facet counts for documents with a year value of 2000, 2001, 2002 through 2004, and all documents with year greater than or equal to 2005:

search?q=star&facet=year&facet-year-constraints=2000,2001,2002..2004,2005..

By default, the response shows the constraints with the highest counts first:

"facets":{
    "year":{"min":1970,"max":2012,
        "constraints":[
            {"value":"2005..","count":8},
            {"value":"2002..2004","count":2},
            {"value":"2001","count":1}
        ]
    }
}