Table of contents

Filters

Filters allow you reduce the number of search results by defining matching criteria on the items.

For example, you can find all items where the last_modified field is between a specific date range.

You can filter full text search results by adding a filters object to the search request object.

POST /api/data/search
{
	"query": "{query}",
	"limit": {limit},
	"page": {page},
    "filters": {
        "terms": [{terms}],
        "multi_terms": [{multi_terms}],
        "ranges": [{ranges}],
        "exists": [{exists}],
        "not_exists": [{exists}]
    }
}
  • The filters object must have at least one property, which is one of the types of filters that may be applied
  • Filters work without a query value, but they are more expensive

There are four types of filters:

  • terms - Find objects where fields match specified terms
  • multi_terms - Find objects where fields match one of many specified terms
  • ranges - Find objects where fields fit within a specified range
  • exists - Find objects that have a value for the specified fields
  • not_exists - Find objects that don’t have a value for the specified fields

terms filters

The filters.terms array allows you to specify a list of terms to match.

For example, to find all objects that have a specified md5 you would make the following request:

POST /api/data/search
{
	"query": "{query}",
    "filters": {
        "terms": [
            {"field":"md5", "value":"2ece57080d9545702d51cf1394b94142"}
        ]
    }
}
  • field - (string) The field to apply the filter to
  • value - (string) The value to match

multi_terms filters

The filters.multi_terms array allows you to specify many values which objects must match.

For example, to find all objects that have an extension of png or jpg, you would make the following request:

POST /api/data/search
{
	"query": "{query}",
    "filters": {
        "multi_terms": [
            {"field":"ext", "value":"png,jpg"}
        ]
    }
}
  • field - (string) The field to apply the filter to
  • value - (string) Comma separated list of values to match

ranges filters

The filters.ranges array allows you to specify a range of values for a given field.

For example, to find all items that were last modified between two dates you would make the following request:

POST /api/data/search
{
	"query": "{query}",
    "filters": {
        "ranges": [
            { "field": "last_modified", "from": "2016-05-24", "to": "now"}
        ]
    }
}
  • field - (string) The field to apply the filter to
  • from - (string) The lower bound of the range to match
  • to - (string) The upper bound of the range to match

"now" is a special value that indicates the current date time.

exists filters

The filters.exists array allows you to specify fields that must appear in the matching items.

Items that do not have a value for the specified field will not appear in the results.

For example, to match all items that have exiv2 metadata, you would make the following request:

POST /api/data/search
{
	"query": "{query}",
    "filters": {
        "exists": ["exiv2"]
    }
}
  • exists - (array of string) List of fields that must exist for an item to appear in the search results

This documentation is generated from the latest version of GrayMeta Platform. For documentation relevant to your own deployed version, please use the documentation inside the application.