@keshava219
Your query can be simplified. You mentioned having a flag in each component node, and if that flag is present, you want to fetch it. You can also check the possible value of the flag. Your query can be as straightforward as follows:
path=/content/<your-path>
1_property=<propertyName>
1...