Perhaps this
?- bagof(item(X,Y),test(X,Y),Items).
Items = [item(1, 1), item(1, 2), item(2, 1), item(2, 2)].
or this
?- bagof(item(Y),test(1,Y),Items).
Items = [item(1), item(2)].
EDIT
An answer by false from StackOverflow seems to be what you seek.
findfirstn(N, Template, Goal_0, Instances) :-
findall(Template, call_firstn(Goal_0, N), Instances).
call_firstn(Goal_0, N) :-
N + N mod 1 >= 0, % ensures that N >=0 and N is an integer
call_nth(Goal_0, Nth),
( Nth == N -> ! ; true ).
Complete example
:- module(examples,
[
findfirstn/4
]).
test(1,a).
test(2,b).
test(3,c).
test(4,d).
findfirstn(N, Template, Goal_0, Instances) :-
findall(Template, call_firstn(Goal_0, N), Instances).
call_firstn(Goal_0, N) :-
N + N mod 1 >= 0, % ensures that N >=0 and N is an integer
call_nth(Goal_0, Nth),
( Nth == N -> ! ; true ).
Example run
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.0)
?- working_directory(_,'C:/Users/Groot').
true.
?- [examples].
true.
?- findfirstn(2,item(X,Y),test(X,Y),Items).
Items = [item(1, a), item(2, b)].
?- findfirstn(3,item(X,Y),test(X,Y),Items).
Items = [item(1, a), item(2, b), item(3, c)].
?- findfirstn(1,item(X,Y),test(X,Y),Items).
Items = [item(1, a)].
?- findfirstn(5,item(X,Y),test(X,Y),Items).
Items = [item(1, a), item(2, b), item(3, c), item(4, d)].
EDIT
Knew this predicate was somewhere just could not remember the name because I never use it, limit/2. (source)
?- bagof(test(X,Y),limit(2,examples:test(X,Y)),Items).
Items = [test(1, a), test(2, b)].
?- bagof(test(X,Y),limit(10,examples:test(X,Y)),Items).
Items = [test(1, a), test(2, b), test(3, c), test(4, d)].