results

Defines the information returned in the JSON response as a result of a Find* command. results has the following parameters, represented as fields in the JSON object:

Parameters

  • [optional] list: specifies the properties of the object that will be returned. The JSON object will list the properties as key-value pairs, respecting the types.

  • [optional] all_properties: Boolean that specifies that all the properties associated with the object will be retrieved. If “true”, list is ignored.

  • [optional] count: Boolean that specifies that only a count of the objects is expected. It returns the total number of objects that matched the search condition.

  • [optional] sum: can be used to request sum of the values retrieved for the given property key. The value can be a single property key or a list of property keys. The result will sum all the values of type Number.

  • [optional] average: can be used to request average of the values retrieved for the given property key. The value can be a single property key or a list of property keys. The result will average all the values of type Number or DateTime.

  • [optional] min: can be used to request min of the values retrieved for the given property key. The value can be a single property key or a list of property keys.

  • [optional] max: can be used to request max of the values retrieved for the given property key. The value can be a single property key or a list of property keys.

  • [optional] group: can be used to group the results together based on the specified property’s values. See below for further details.

If group_by_source is set to True and the results parameter has any of these specified: count, sum, average, min, max and group, query returns with an error.

Examples

# Get "name" and "format" properties of all the objects
"results": {
    "list": ["name", "format"],
}

# Return only the number of results
"results": {
    "count": true
}

# Return the average the value of those for the age property
"results": {
    "average": "age",
}

# Returns the sum of the "number_of_cars" properties for all entities
"results": {
    "sum": "number_of_cars",
}

# Return the minimum and maximum value of those for the age property
"results": {
    "min": "age",
    "max": "age",
}

# Return the minimum and maximum value of those for the age, height and weight properties
"results": {
    "min": ["height", "weight", "age"],
    "max": ["height", "weight", "age"],
}

# Return only the first 150 objects, and sort them by email
"results": {
    "list": ["name", "format"],
}

Group Example

group statement groups results that have the same values for specified properties. group is often used with aggregate functions (count, sum, average, min, max) to group the result-set by one or more properties.

[ {
    "FindImage": {
        "constraints": {
            "year_captured": [ ">=", 1870 ]
        },
        "results": {
            "group": ["year_caputured"]
        }
    }
}]

# Response:

[ {
    "FindImage": {
        "groups": [
            {
                "_group_class": "_Image",
                "_group_count": 34,
                "year_captured": 1875

            },
            {
                "_group_class": "_Image",
                "_group_count": 28,
                "year_captured": 1876
            }
        ]
    }
}]
[ {
    "FindImage": {
        "constraints" : {
            "year_captured": [ ">=", 1870 ]
        },
        "results": {
            "group": ["year_caputured", "event"]
        }
    }
}]

# Response:

[ {
    "FindImage": {
        "groups": [
            {
                "_group_class": "_Image",
                "_group_count": 34,
                "year_captured": 1875,
                "event": "April Festival",
            },
            {
                "_group_class": "_Image",
                "_group_count": 20,
                "year_captured": 1875,
                "event": "April Festival",
            },
            {
                "_group_class": "_Image",
                "_groupcount": 28,
                "year_captured": 1874,
                "event": "June Festival",
            }
        ]
    }
}]
[ {
    "FindImage": {
        "constraints" : {
            "year_captured": [ ">=", 1870 ]
        },
        "results": {
            "group": ["year_caputured", "event"]
            "sum": "number_of_people"
        }
    }
}]

# Response:

[ {
    "FindImage": {
        "groups": [
            {
                "_group_class": "Person",
                "_group_count": 34,
                "_group_sum": {
                    "number_of_people": 42
                },
                "year_captured": 1875,
                "event": "April Festival",
            },
            {
                "_group_class": "Person",
                "_groupcount": 20,
                "_group_sum": {
                    "number_of_people": 42
                },
                "year_captured": 1875,
                "event": "April Festival",
            },
            {
                "_group_class": "Person",
                "_groupcount": 28,
                "_group_sum": {
                    "number_of_people": 42
                },
                "year_captured": 1874,
                "event": "June Festival",
            }
        ]
    }
}]
[ {
    "FindImage": {
        "constraints" : {
            "year_captured": [ ">=", 1870 ]
        },
        "results": {
            "group": ["year_caputured", "event"]
            "sum": ["number_of_people", "number_of_cats"],
            "average": "number_of_people"
        }
    }
}]

# Response:

[ {
    "FindImage": {
        "groups": [
            {
                "_group_class": "Person",
                "_group_count": 34,
                "_group_sum": {
                    "number_of_people": 42,
                    "number_of_cats":   2,
                },
                "_group_avg": {
                    "number_of_people": 1.23,
                },
                "year_captured": 1875,
                "event": "April Festival"
            },
            {
                "_group_class": "Person",
                "year_captured": 1875,
                "_groupcount": 20,
                "_group_sum": {
                    "number_of_people": 82,
                    "number_of_cats":   1,
                },
                "_group_avg": {
                    "number_of_people": 4.1,
                },
                "event": "April Festival"
            },
            {
                "_group_class": "Person",
                "_groupcount": 28,
                "_group_sum": {
                    "number_of_people": 35,
                    "number_of_cats":   5,
                },
                "_group_avg": {
                    "number_of_people": 1.25,
                },
                "year_captured": 1874,
                "event": "June Festival"
            }
        ]
    }
}]