JAVA SDK vs REST API different results

Okay, so first your custom environment doesn’t make much sense, just use the default one.
Next, do not close the bucket until you finished all your stuff

Finally, the code as it stands here will trigger a key=["KEY, “KEY2”] I don’t think thats what you want unless the key you emit in a view is like emit(["KEY, “KEY2”,null); and NOT two separate emits.

Are you sure that you actually don’t want “keys” instead of key? if you use keys, then rows with either “KEY” or “KEY2” will be returned.