0

Lets say I have a node with a property, Event, that is assigned a StringArray. I am trying to extract '6013' and '6005' that were assigned from a collection when the node was created ( see below for creation query code) and assign them to as another property.

I tried using SPLIT but it does not work with what neo4j refers to as StringArray.

Event: ["EventLog/6013", "EventLog/6005"]

Creation Query: Event assigned from collection

... WITH act.timestamp as timestamp, COLLECT(DISTINCT act.message) as messages, COLLECT(DISTINCT obt.filename) as filenames, COLLECT(act) as acts CREATE (a{ Event: filenames, Description:messages, timestamp:timestamp}) FOREACH (act in acts | CREATE (act)-[:LINK]->(a))

Desired Node:

Event: ["EventLog/6013", "EventLog/6005"] Assinged: [6013, 6005]

N6DYN
  • 325
  • 1
  • 3
  • 17
  • Just a note, there's really never any good case for creating a node without a label. Definitely add a label in your CREATE clause for the node, that way you can look up that node faster when supplying the label (using a label scan), and if quicker lookup is needed you can create an index on a label/property combination. – InverseFalcon Oct 23 '18 at 05:16

1 Answers1

2

You can list comprehension to do an extraction/transformation of each item in your list (extract() can do the same, but I prefer the list comprehension syntax).

From there it's a matter of what rules to follow to get the value you need from the string.

If the values are always 4 digits, and there's never any trailing whitespace, then you can use right(event, 4) to get the last 4 characters of the string.

If the digits can be of varied size, but the prefix for each string is always "EventLog/", then you can use substring(event, 9) to get the substring after the 9th character.

If the prefix could vary and all you knew was that the part you wanted was after the first "/" character, then you could use split(), getting the second part of the resulting list like this: split(event, '/')[1].

In any case, if you wanted the value as an integer rather than a string, you'd need to use toInteger() on the result.

Here's an example of using list comprehension using the right() function:

WITH ["EventLog/6013", "EventLog/6005"] as events
RETURN [event in events | toInteger(right(event, 4))] as extractedValues
InverseFalcon
  • 29,576
  • 4
  • 38
  • 51