Jay Park
Jay Park

Reputation: 348

How to merge multiple filed which contain null value

1.I'm trying to import JSON file and create a graph but value.replyto_user_id replyto_id contain null value,

CALL apoc.load.json("file:///tweets.json")
YIELD value
MERGE (t:Tweets
{
id: value.id,
created_at: value.created_at,
text: value.text,
user_id: value.user_id,
retweet_id: value.retweet_id,
retweet_user_id: value.retweet_user_id,
user_mentions: value.user_mentions,
replyto_id: value.replyto_id,
replyto_user_id: value.replyto_user_id
}
)

2.Erro message: Cannot merge node using null property value. Then I tired

CALL apoc.load.json("file:///tweets.json")
YIELD value 
with value where value.replyto_user_id and replyto_id  is not null
{
id: value.id,
created_at: value.created_at,
text: value.text,
user_id: value.user_id,
retweet_id: value.retweet_id,
retweet_user_id: value.retweet_user_id,
user_mentions: value.user_mentions,
replyto_id: value.replyto_id,
replyto_user_id: value.replyto_user_id
}
)

Upvotes: 0

Views: 115

Answers (2)

cybersam
cybersam

Reputation: 66989

When you MERGE a node, you should only specify the properties that uniquely identify that node. That way, if the node already existed but some non-identifying properties have different values, the MERGE will not create a new node.

I will assume that in your data model the id property value uniquely identifies a Tweet node (renamed from Tweets, since each node represents just one tweet).

Also, I will assume that you want to set to the non-identifying properties only when a Tweet node is first created. To ensure that, the query below uses ON CREATE.

CALL apoc.load.json("file:///tweets.json") YIELD value
MERGE (t:Tweet {id: value.id})
ON CREATE SET t += value{
  .created_at, .text, .user_id, .retweet_id, .retweet_user_id,
  .user_mentions, .replyto_id, .replyto_user_id}

Upvotes: 0

Graphileon
Graphileon

Reputation: 5385

To avoid duplications of tweets, you do not have to include all properties in the MERGE. Just the id that uniquely identifies the tweet.

MERGE (t:Tweets {id:value.id})
SET t.prop1= value.prop1,
        t.prop2= value.prop2

should do it, and you do not have to worry about nulls.

Make sure you have an index / constraint set on Tweets.id

Upvotes: 1

Related Questions