amazon-web-servicesfacetamazon-cloudsearch

How to get grouped facet result from Amazon CloudSearch with structured query


I am trying to get grouped facet information in following situation :

When query requests cars with certain makes (e.g) HONDA or MAZDA), with make and model facet information then query would be like

q={or "make":"HONDA" "make":"MAZDA"}&facet.make={}&facet.model={}

Then, its facet result would be like:

"make" : {
    "buckets" : [{
            "value" : "HONDA",
            "count" : 200
        }, {
            "value" : "MAZDA",
            "count" : 100
        }
    ]
},
"model_display" : {
    "buckets" : [{
        value" : "6",
            "count" : 20
        }, {
            "value" : "2",
            "count" : 30
        },
        {
            "value" : "3",
            "count" : 50
        },
            "value" : "CIVIC",
            "count" : 100
        }, {
            "value" : "ACCORD",
            "count" : 50
        },
        {
            "value" : "CR-V",
            "count" : 50
        },
    }]
}

However, I really wonder if there is any way to get facet result like following:

"model_display" : {
"buckets" : [{
    "HONDA":{
        "value" : "CIVIC",
        "count" : 100
    }, {
        "value" : "ACCORD",
        "count" : 50
    },{
        "value" : "CR-V",
        "count" : 50
    },
},
{
    "MAZDA":{
        "value" : "6",
        "count" : 20
    }, {
        "value" : "2",
        "count" : 30
    },{
        "value" : "3",
        "count" : 50
    },
}
]}

Solution

  • The only way to do this is with multiple queries, one per "make":

    q=make:'HONDA'&facet.model={}
    
    q=make:'MAZDA'&facet.model={}