@evelandi,
search takes the terms given as literal and hence even though you assign some value to the variables. In the above example, your final search will still be index=id1 and not the value. You may verify that from job inspector.
To make the above search work, you can use where which work as conditional expressions
sourcetype=companyNames Key=100001
| eval id1= Key."-cc"
| where sourcetype=groups AND index=id1
| table groupId,groupName
However, looking at your original requirement, you may try
sourcetype=groups [ sourcetype=companyNames |"search for all keys"|eval id1= Key."-cc"|rename id1 as index ]
Final search will be formulated as sourcetype=groups (index=100001 OR index=100002)
... View more