Besides and before anything else, you shouldn't use "numbers" with set, if not in an interactive session:
You never know which item is actually 1 or 2.
Generally speaking the "correct" way is to use find to select an item from one unique characteristic (like name, address, comment, etc.), see:
but in your case you can probably use port names directly (if this is what you want to obtain) i.e.:
/interface ethernet switch port
set ether1 vlan-type=edge-port
set ether2 vlan-type=edge-port