Minecraft wiki entry for Target_selectors, associated text: [hasitem={<argument>=<value>,<argument2>=<value2>,...}] — Include only targets that have the specified items.
[hasitem=[{<argumentA>=<valueA>,...},{<argumentB>=<valueB>,...}]] — Include only targets that have item A and item B, etc.
All acceptable arguments are as follows:
item
Must be an item ID.
Currently dosen't work on concrete powder.
data
Specifies the item data for the item(s). Must be a 32-bit integer number. Values which are invalid for the specified item id will default to 0. If not specified, defaults to 0.
Note that because it defaults to 0, selectors like {item=potion} can only target water bottol, though {item=potion,data=1} can target mundane potion.
Currently dosen't work on blocks' direct item forms (e.g. dirt, stone). For these items, data is always considered as invalid and defaults back to 0, and aux value of these items in inventory are also always considered as 0. That means you can't target items like coase dirt, green wool solely.
For potion and tipped arrow, aux value represents the data value of potion effect, and currently invalid values crash the game.
quantity
Specifies the amount of the items the entity has. Must be an integer range (e.g. 1 - exact match of 1. ..5 - less than or equal to 5. 5.. - more than or equal to 5. 0..5 - between 0 and 5, inclusive.).
! can be uesd to invert selection. For example, {item=apple,quantity=!5} can exclusive entities who have five apples.
When not specified, defaults to quantity=1... When quantity=0, entities must have 0 the specified item (i.e. do not have the specified item) to be targeted.
location and slot
Specifies the inventory slot to be test. Valid values are the same as for slot arguments in /replaceitem.
Specifying slot without location is invalid.
slot must be an integer range. (e.g. 1 - exact match of 1. ..5 - less than or equal to 5. 5.. - more than or equal to 5. 0..5 - between 0 and 5, inclusive.)