# Does switch node support a "full text" search of message?

**URL:** <https://discourse.nodered.org/t/does-switch-node-support-a-full-text-search-of-message/68596>\
**Category:** General\
**Created:** [5 October 2022 11:21 UTC](https://discourse.nodered.org/t/does-switch-node-support-a-full-text-search-of-message/68596 "2022-10-05T11:21:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamueller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tamueller/32/68690_2.png) [@tamueller](https://discourse.nodered.org/u/tamueller)\
**Post date:** [5 October 2022 11:21 UTC](https://discourse.nodered.org/t/does-switch-node-support-a-full-text-search-of-message/68596/1 "2022-10-05T11:21:53Z")

</div>

Hi,  
I'm new to red node and stumbled upon a problem where my switch node using "contains" does not work as expected.  
I have a device that sends a message like this:  
`{"action":"up_press","action_duration":null,"battery":77,"linkquality":174,"update":{"state":"idle"},"update_available":null}`

I use a switch node with property: msg.payload and contains "up\_", but that doesnt work. If I use property.payload.action, it works. I understand that action is nested within payload, but why does **contains** not do a recursive or full text search? I'd expect it to get the whole JSON object, and the object contains "up\_".  
So, two questions:  
a) What is the conceptual reason why it is done this way, so I can learn more about node reds way of thinking.  
b) how can I achieve a recursive or full body search with a switch node (in case I don't know exactly where the text will be)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [5 October 2022 11:37 UTC](https://discourse.nodered.org/t/does-switch-node-support-a-full-text-search-of-message/68596/2 "2022-10-05T11:37:23Z")

</div>

The `contains` rule expects to operate on a string. It doesn't do a full search of arbitrary nested properties.

> [@tamueller](#):
>
> What is the conceptual reason why it is done this way,

Because it was added as a way to check if a string property contains some text. It just wasn't considered as an operation to search into an object's properties. You are the first person I can recall asking otherwise.

> [@tamueller](#):
>
> b) how can I achieve a recursive or full body search with a switch node (in case I don't know exactly where the text will be)

Off the top of my head, the only solution I can thnk of is to first use the JSON node to convert the object to a single JSON string that the Switch node can then search it as a single property.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 October 2022 11:54 UTC](https://discourse.nodered.org/t/does-switch-node-support-a-full-text-search-of-message/68596/3 "2022-10-05T11:54:02Z")

</div>

> [@knolleary](#):
>
> The `contains` rule expects to operate on a string. It doesn't do a full search of arbitrary nested properties.

I must admit that's a surprise, I'd expect it to search whatever it is passed.

Is the same true for "Matches regex"?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [5 October 2022 12:53 UTC](https://discourse.nodered.org/t/does-switch-node-support-a-full-text-search-of-message/68596/4 "2022-10-05T12:53:31Z")

</div>

> [@jbudd](#):
>
> Is the same true for "Matches regex"?

Yes. Strings can be tested against a regex - objects cannot.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 October 2022 12:54 UTC](https://discourse.nodered.org/t/does-switch-node-support-a-full-text-search-of-message/68596/5 "2022-10-19T12:54:00Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
