'NodeRed: How to filter a message based on the value in a variable array in a subproperty
My Home Assistant pulls various RSS news feeds. The messages coming from the corresponding node contain an array payload.event.tags which is of variable length and contains a term property for each element. There can be one tag or 20. I want to filter the messages by those term property without limiting the output to the tags array. I.e. if the term in any tags-array member matches my keywords, I want the whole message to pass through.
I have tried to use the "Filter As An Array Of Messages" option of the filter node but that leads to only the matching array members coming out, not the original message. Also, the filter node does not seem to like wildcards e.g. payload.event.tags[*].term in the property field.
Here is an example of a whole message:
{
"payload": {
"event_type": "feedreader",
"event": {
"links": [{
"rel": "alternate",
"type": "text/html",
"href": "https://www.hs.fi/urheilu/art-2000008597271.html"
}, {
"type": "image/jpeg",
"length": "0",
"href": "https://hs.mediadelivery.fi/img/1440/ee96178249af06cbecdae023ac99b55c.jpg",
"rel": "enclosure"
}],
"link": "https://www.hs.fi/urheilu/art-2000008597271.html",
"title": "Jääkiekko | Tuore tieto – Marko Anttilan vapautuminen koronakaranteenista voi olla enää tunneista kiinni",
"title_detail": {
"type": "text/plain",
"language": null,
"base": "https://www.hs.fi/rss/tuoreimmat.xml",
"value": "Jääkiekko | Tuore tieto – Marko Anttilan vapautuminen koronakaranteenista voi olla enää tunneista kiinni"
},
"summary": "Tiukalla koronatestauksen ct-rajalla olisi koko Pekingin jääkiekkoturnaus ollut vaarassa.",
"summary_detail": {
"type": "text/html",
"language": null,
"base": "https://www.hs.fi/rss/tuoreimmat.xml",
"value": "Tiukalla koronatestauksen ct-rajalla olisi koko Pekingin jääkiekkoturnaus ollut vaarassa."
},
"media_content": [{
"url": "https://hs.mediadelivery.fi/img/1440/ee96178249af06cbecdae023ac99b55c.jpg",
"type": "image/jpeg",
"width": "1440"
}],
"tags": [{
"term": "Urheilu",
"scheme": null,
"label": null
}],
"published": "Tue, 08 Feb 2022 12:02:00 +0200",
"published_parsed": [2022, 2, 8, 10, 2, 0, 1, 39, 0],
"id": "hs-2000008597271",
"guidislink": false,
"feed_url": "https://www.hs.fi/rss/tuoreimmat.xml"
},
"origin": "LOCAL",
"time_fired": "2022-02-08T10:06:33.611397+00:00",
"context": {
"id": "3635068a57cf164c075745ac0f35141b",
"parent_id": null,
"user_id": null
}
},
"topic": "feedreader",
"_msgid": "5b2b0167122af4e2"
}
And an example of a message with more than one tag:
{
"payload": {
"event_type": "feedreader",
"event": {
"title": "Some ruokkii mielenterveysongelmien \"itsediagnosointia\", mutta väärään tietoon on helppo haksahtaa",
"title_detail": {
"type": "text/plain",
"language": null,
"base": "https://feeds.yle.fi/uutiset/v1/majorHeadlines/YLE_UUTISET.rss",
"value": "Some ruokkii mielenterveysongelmien \"itsediagnosointia\", mutta väärään tietoon on helppo haksahtaa"
},
"links": [{
"rel": "alternate",
"type": "text/html",
"href": "https://yle.fi/uutiset/3-12302419?origin=rss"
}, {
"type": "image/jpeg",
"length": "0",
"href": "https://images.cdn.yle.fi/image/upload//w_205,h_115,q_70/39-7109395f41ad5047cb5.jpg",
"rel": "enclosure"
}],
"link": "https://yle.fi/uutiset/3-12302419?origin=rss",
"summary": "Entistä useampi hakeutuu mielenterveyspalveluihin \"valmiin\" diagnoosin kanssa. Tiedon etsiminen on helpompaa kuin koskaan, mutta se ei korvaa oikeaa diagnoosia, varoittaa asiantuntija.",
"summary_detail": {
"type": "text/html",
"language": null,
"base": "https://feeds.yle.fi/uutiset/v1/majorHeadlines/YLE_UUTISET.rss",
"value": "Entistä useampi hakeutuu mielenterveyspalveluihin \"valmiin\" diagnoosin kanssa. Tiedon etsiminen on helpompaa kuin koskaan, mutta se ei korvaa oikeaa diagnoosia, varoittaa asiantuntija."
},
"content": [{
"type": "text/html",
"language": null,
"base": "https://feeds.yle.fi/uutiset/v1/majorHeadlines/YLE_UUTISET.rss",
"value": "<p class=\"yle__article__paragraph\">Yhä useampi hakeutuu mielenterveyspalveluihin niin, että taustalla on valmis ajatus omasta diagnoosista. Yhä yleisempää on myös mielenterveysongelmien "itsediagnosointi".</p>\n<p class=\"yle__article__paragraph\">Itsediagnosointi, englanniksi self-diagnosis, tarkoittaa ajatusta siitä, että voi ajatella kärsivänsä esimerkiksi adhd:sta tai ahdistushäiriöstä, vaikkei ole saanut varsinaista ammattilaisen tekemää diagnoosia.</p>\n<p class=\"yle__article__paragraph\">Korkeakouluopiskelijoiden terveydenhuollosta vastaavassa Ylioppilaisen terveydenhuoltosäätiö YTHS:ssä on huomattu, että apua haetaan yhä useammin "valmiin diagnoosin" kanssa, kertoo YTHS:n mielenterveystyön johtava ylilääkäri <strong class=\"yle__article__strong\">Tommi Väyrynen</strong>.</p>\n<p class=\"yle__article__paragraph\">– On tullut tavallisemmaksi, että opiskelija tulee vastaanotolle aika vahvalla epäilyllä, että hänellä on jokin tietty ongelma. Joillakin on myös aika selkeä ..."
}],
"published": "Tue, 08 Feb 2022 12:10:11 +0200",
"published_parsed": [2022, 2, 8, 10, 10, 11, 1, 39, 0],
"tags": [{
"term": "mielenterveys",
"scheme": null,
"label": null
}, {
"term": "masennus",
"scheme": null,
"label": null
}, {
"term": "psykologia",
"scheme": null,
"label": null
}, {
"term": "tunne-elämä",
"scheme": null,
"label": null
}, {
"term": "mielenterveysongelmat",
"scheme": null,
"label": null
}, {
"term": "diagnoosi",
"scheme": null,
"label": null
}, {
"term": "nuoret aikuiset",
"scheme": null,
"label": null
}, {
"term": "ahdistuneisuushäiriöt",
"scheme": null,
"label": null
}, {
"term": "sosiaalinen media",
"scheme": null,
"label": null
}, {
"term": "Tiktok",
"scheme": null,
"label": null
}, {
"term": "kotimaa",
"scheme": null,
"label": null
}, {
"term": "terveys",
"scheme": null,
"label": null
}],
"id": "https://yle.fi/uutiset/3-12302419",
"guidislink": false,
"feed_url": "https://feeds.yle.fi/uutiset/v1/majorHeadlines/YLE_UUTISET.rss"
},
"origin": "LOCAL",
"time_fired": "2022-02-08T10:16:36.472432+00:00",
"context": {
"id": "2bee9ad3c6e191879a437d2fde34d2ab",
"parent_id": null,
"user_id": null
}
},
"topic": "feedreader",
"_msgid": "773a3a038e81650c"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
