Help Center> EventGrid> User Guide> Event Rules> Example Filter Rules
Updated on 2023-04-26 GMT+08:00

Example Filter Rules

This section provides examples of filter rules of all matching types.

These matching types are available:

Exact Match

Filter events that exactly match a specified string. As shown in the following table, events whose source is HC.OBS are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}
{
    "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}]
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}

Filter events that exactly match a specified number. As shown in the following table, events whose age in data is 10 are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "age":10
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "age":[{
	     "op": "NumberIn",
	     "values":[10] 
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "age":10
	}
    }]
}

Exclusion Match

Filter events that do not match a specified string. As shown in the following table, events whose type is not object:get are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}
{
    "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
    "type": [{
	   "op": "StringNotIn",
	   "values": ["object:get"]
	}]
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}

Filter events that do not match a specified number. As shown in the following table, events whose age in data is not 11 are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "age":10
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
"age":[{
	     "op": "NumberNotIn",
	     "values":[11]
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "age":10
	}
    }]
}

Prefix Match

Filter events whose prefix matches a specified value. As shown in the following table, events whose type starts with object: are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
    "type": [{
	   "op": "StringStartsWith",
	   "values": ["object:"]
	}]
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}

Prefix Not Matching

Filter events whose prefix does not match a specified value. As shown in the following table, events whose source does not start with HC are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
    "source": [{
       "op": "StringNotStartsWith",
       "values": ["HC"]
	}]
} 

None

Suffix Match

Filter events whose suffix matches a specified value. As shown in the following table, events whose subject ends with jpg are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
    "subject": [{
	   "op": "StringEndsWith",
	   "values": ["jpg"]
	}]
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}

Suffix Not Matching

Filter events whose suffix does not match a specified value. As shown in the following table, events whose subject does not end with txt are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
    "subject":[{
	 "op": "StringNotEndsWith",
	 "values": ["txt"]
	}]
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable"
	}
    }]
}

Value Range Match

Filter events that match a specified value range. As shown in the following table, events whose size in data is less than 20 are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "size":[{
	     "op": "NumberLessThan",
	     "value":20
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}

As shown in the following table, events whose size in data is greater than or equal to 2 are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "size":[{
	     "op": "NumberNotLessThan",
	     "value":2
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}

As shown in the following table, events whose size in data is greater than 9 are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "size":[{
	     "op": "NumberGreaterThan",
	     "value":9
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}

As shown in the following table, events whose size in data is less than or equal to 9 are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "size":[{
	     "op": "NumberNotGreaterThan",
	     "value":9
           }]
  }
} 

None

As shown in the following table, events whose size in data is from 1 to 20 are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "size":[{
	     "op": "NumberInRange",
	     "values":[
                  [
                    1,
                    20
                  ]
              ]
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}

As shown in the following table, events whose size in data is less than 1 or greater than 20 are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "size":[{
	     "op": "NumberNotInRange",
	     "values":[
                  [
                    1,
                    20
                  ]                      
              ]
           }]
  }
} 

None

Null Match

Filter events with a null value or undefined field. As shown in the following table, events whose size and age in data are null or undefined are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":  null
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "size":[{
	     "op": "IsNull"
           }],
    "age":[{
	     "op": "IsNull"
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":null
	}
    }]
}

Non-null Match

Filter events whose certain field is not null. As shown in the following table, events whose size and name in data are not null are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size": 10
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "size":[{
	     "op": "IsNotNull"
           }],
    "name":[{
	     "op": "IsNotNull"
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size":10
	}
    }]
}

True Match

Filter events whose certain field is true. As shown in the following table, events whose size and name in data are true are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": true,
		"state": "enable",
                "size": true
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "size":[{
	     "op": "IsTrue"
           }],
    "name":[{
	     "op": "IsTrue"
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": true,
		"state": "enable",
                "size":true
	}
    }]
}

Non-true Match

Filter events whose certain field is not true. As shown in the following table, events whose name in data is not true are matched.

Event from Source

Filter Rule

Matched Event

{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size": null
	}
    }]
}
{
   "source": [{
	   "op": "StringIn",
	   "values": ["HC.OBS"]
	}],
  "data":{
    "name":[{
	     "op": "IsNotTrue"
           }]
  }
} 
{
    "events":[{
	"id": "4b26115b-778e-11ec-******",
        "specversion": "1.0",
	"source": "HC.OBS",
	"type": "object:put",
	"datacontenttype": "application/json",
	"subject": "xxx.jpg",
	"time": "2022-01-17T12:07:00.955Z",
	"data": {
		"name": "test01",
		"state": "enable",
                "size": null
	}
    }]
}