If I'm understanding what your trying to do correctly, it sounds like you want to launch a sub-search for each and every event returned by your base search ( sourcetype=foo ). It also looks like you only want the sub-search to run conditionally if you don't have a valid clientIP value. Does that sound correct?
First off, I don't think there is any way to conditionally launch a subsearch. Each subsearch is only run once, and is evaluated and expanded into the main search, and then the main search runs. Now, you can launch a search per-event using the map command, so you may need to do something like that, however in that case, the output from the individual "map" run search is our final output, so you lose all the events from your base search in the output. So, you'll need to do all of this inside of a sub-search and then recombine the two sets of results using a join command, or something...
For the record, this is a complete guess. This would take lots of examples and probably a few hours of messing around to get something that actually works properly...
sourcetype=foo | join type=outer user [ search sourcetype=foo clientIP=="x.x.x.x" | map search="search earliest=$earliest$ latest=$latest$ sourcetype=proxy user=$username$" | fields _time, clientIP, user ]
I'm not sure if you can get join to do the correct time correlation that you need. It's possible that you'll need to do some sort of funky transaction instead (since it's the only search command that lets you pull events together based on a range of time, but there are also a number of down-sides to that approach.)
Good luck 😉
Alternate approaches: Don't forget that you can always programatically call splunk searches. It sounds like you have something complex enough that it may warrant that kind of effort, and that would give you FULL control. It's also possible that generating lookups periodically could be a much better way to handle this.
... View more