How do I use the execute command against a named entity?

I would like to do /execute @e[type=Arrow,CustomName:"Flare"] ~ ~ ~ (very long command that I am doing) but it doesn't let me. Whats wrong with it?


CustomName is a NBT tag for entities, not a target selector argument. To select a entity with a custom name via target selector you need to use @e[name=<CustomName>].

If you wish to use the NBT tag or multiple NBT tags to select a entity, you need to create a scoreboard objective in which you set the entities with the desired NBT tag using the Partial NBT Test parameter of scoreboard, then select the entities with the specified score:

Setup:

 /scoreboard objectives add selector dummy

Clock (20 tps):

 /scoreboard players set @e selector 0 //Reset the score
 /scoreboard players set @e selector 1 {<Desired NBT Tags>} //Set the score of all entities with the specified NBT Tags to 1
 /execute @e[score_selector_min=1] <x> <y> <z> <Command> //Selects all entities that have been marked by the last command block and executes a command on them