@Bernnt
Try this version instead - hopefully it is closer to your requirements
It doesnt mangle or flatten the original data (its stored in original format in flow context)
The search routines search the original data.
The return is always an array containing all objects found that match your search criteria.
If you need a specific item from the result, find it in the debug msg, use the "copy path" button
flow...
[{"id":"81d62991.c28128","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"Init","payloadType":"str","x":150,"y":260,"wires":[["5c782e34.536cd"]]},{"id":"5c782e34.536cd","type":"file in","z":"c479d7d3.fce8d8","name":"","filename":"c:/temp/SearchResults.xml","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":350,"y":260,"wires":[["408f6d3b.017944"]]},{"id":"408f6d3b.017944","type":"xml","z":"c479d7d3.fce8d8","name":"","property":"payload","attr":"","chr":"","x":560,"y":260,"wires":[["5ef24e86.83332"]]},{"id":"5ef24e86.83332","type":"change","z":"c479d7d3.fce8d8","name":"","rules":[{"t":"set","p":"studydata","pt":"flow","to":"payload.search_results.study","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":260,"wires":[[]]},{"id":"ce4e8cef.b3c4a","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Anesthesia","payloadType":"str","x":160,"y":360,"wires":[["a328617b.422e"]]},{"id":"51739fff.279b6","type":"comment","z":"c479d7d3.fce8d8","name":"1. Load XML data, store it in flow.conditions","info":"","x":240,"y":220,"wires":[]},{"id":"25e1145d.1ca0dc","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Food Habits","payloadType":"str","x":170,"y":400,"wires":[["a328617b.422e"]]},{"id":"3664026f.ed7f9e","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"_wont_find_me_","payloadType":"str","x":180,"y":480,"wires":[["a328617b.422e"]]},{"id":"744fa604.4422c8","type":"function","z":"c479d7d3.fce8d8","name":"exact search (exists true/false)","func":"var findWhat = msg.payload;\nvar data = msg.studydata;\nmsg.payload = data.filter(e => {\n try {\n var conditions = e.conditions[0].condition\n if(conditions.includes(findWhat)) {\n return true;\n }\n } catch {\n \n }\n return false\n});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":360,"wires":[["d11e148d.d87bb8","30041c9c.853d44"]]},{"id":"a328617b.422e","type":"change","z":"c479d7d3.fce8d8","name":"","rules":[{"t":"set","p":"studydata","pt":"msg","to":"studydata","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":360,"wires":[["744fa604.4422c8","d5a4ad29.38883","607e9988.3398c8","48bbe978.ef6f98"]]},{"id":"d5a4ad29.38883","type":"function","z":"c479d7d3.fce8d8","name":"partial search (exists true/false)","func":"\nvar findWhat = msg.payload;\nvar data = msg.studydata;\nmsg.payload = data.filter(e => {\n try {\n var conditions = e.conditions[0].condition;\n var found = conditions.some(e => {\n return (e && e.length) ? e.includes(findWhat) : false\n })\n return found;\n } catch {\n }\n return null\n});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":480,"wires":[["72e94dd8.cfab74"]]},{"id":"d11e148d.d87bb8","type":"debug","z":"c479d7d3.fce8d8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload[0].title","targetType":"msg","statusVal":"payload","statusType":"auto","x":1010,"y":360,"wires":[]},{"id":"72e94dd8.cfab74","type":"debug","z":"c479d7d3.fce8d8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload[0].title","targetType":"msg","statusVal":"payload","statusType":"auto","x":1010,"y":480,"wires":[]},{"id":"5df2abd6.e1bb94","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Quality Imp","payloadType":"str","x":170,"y":520,"wires":[["a328617b.422e"]]},{"id":"607e9988.3398c8","type":"function","z":"c479d7d3.fce8d8","name":"partial search (exists true/false) (case insensitive)","func":"var findWhat = msg.payload.toLowerCase();\nvar data = msg.studydata;\nmsg.payload = data.filter(e => {\n try {\n var conditions = e.conditions[0].condition;\n var found = conditions.some(e => {\n return (e && e.length) ? e.toLowerCase().includes(findWhat) : false\n })\n return found;\n } catch {\n }\n return null\n});\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":710,"y":540,"wires":[["c8cd13ba.4b378","7c039174.c795d"]]},{"id":"c8cd13ba.4b378","type":"debug","z":"c479d7d3.fce8d8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload[0].title","targetType":"msg","statusVal":"payload","statusType":"auto","x":1010,"y":540,"wires":[]},{"id":"463f9ee6.77792","type":"comment","z":"c479d7d3.fce8d8","name":"2. Perform the search","info":"","x":180,"y":320,"wires":[]},{"id":"f4af84b8.e507b8","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"fOOd HaBiTs","payloadType":"str","x":170,"y":440,"wires":[["a328617b.422e"]]},{"id":"e3c813b1.cf5e7","type":"comment","z":"c479d7d3.fce8d8","name":"FIRST - change the file path to your XML file","info":"","x":250,"y":180,"wires":[]},{"id":"48bbe978.ef6f98","type":"function","z":"c479d7d3.fce8d8","name":"exact search (exists true/false) (case insensitive)","func":"var findWhat = msg.payload.toLowerCase();\nvar data = msg.studydata;\nmsg.payload = data.filter(e => {\n try {\n var conditions = e.conditions[0].condition;\n var found = conditions.some(e => {\n return (e && e.length) ? e.toLowerCase() === findWhat : false\n })\n return found;\n } catch {\n }\n return null\n});\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":700,"y":420,"wires":[["c7354317.cf208"]]},{"id":"c7354317.cf208","type":"debug","z":"c479d7d3.fce8d8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload[0].title","targetType":"msg","statusVal":"payload","statusType":"auto","x":1010,"y":420,"wires":[]},{"id":"9fc765ca.fac068","type":"comment","z":"c479d7d3.fce8d8","name":"This version doesnt flatten the original data - instead, it searches the original data and returns ANY item it finds","info":"","x":450,"y":60,"wires":[]},{"id":"2fdc2330.67c33c","type":"comment","z":"c479d7d3.fce8d8","name":"That way, you have full access to ALL items related to the found text","info":"","x":320,"y":100,"wires":[]},{"id":"e71be32f.9d4ab","type":"inject","z":"c479d7d3.fce8d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"quality imp","payloadType":"str","x":160,"y":560,"wires":[["a328617b.422e"]]},{"id":"30041c9c.853d44","type":"switch","z":"c479d7d3.fce8d8","name":"Found?","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":870,"y":320,"wires":[["19b7b63f.b0b46a"]]},{"id":"19b7b63f.b0b46a","type":"debug","z":"c479d7d3.fce8d8","name":"first found item","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[0]","targetType":"msg","statusVal":"","statusType":"auto","x":1040,"y":320,"wires":[]},{"id":"7c039174.c795d","type":"switch","z":"c479d7d3.fce8d8","name":"Found?","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":860,"y":600,"wires":[["f6d949dd.411978"]]},{"id":"f6d949dd.411978","type":"debug","z":"c479d7d3.fce8d8","name":"first found item","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload[0]","targetType":"msg","statusVal":"","statusType":"auto","x":1030,"y":600,"wires":[]}]