# Slow merge and match when I use unwind

**URL:** <https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated\
**Created:** [November 14, 2022, 1:12pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962 "2022-11-14T13:12:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AhmedMahfouz](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@AhmedMahfouz](https://community.neo4j.com/u/AhmedMahfouz)\
**Post date:** [November 14, 2022, 1:12pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/1 "2022-11-14T13:12:57Z")

</div>

Hello,

when I run this code

call apoc.load.jsonParams(uri, options,null)

YIELD value AS listing

MERGE (l:Listing{cid:listing.results[0].listing\_id})

it takes 24s to done although I created indexes on that . when I run MERGE (l:Listing{cid:}) as normal query it takes only 1 ms

any idea ?

---

<div class="post-metadata">

**Author:** ![AhmedMahfouz](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@AhmedMahfouz](https://community.neo4j.com/u/AhmedMahfouz)\
**Post date:** [November 14, 2022, 6:28pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/2 "2022-11-14T18:28:54Z")

</div>

When I am not using apoc it works with indexes and when I use apoc it hits on all node (doesn't use indexes)

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 14, 2022, 1:40pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/3 "2022-11-14T13:40:17Z")

</div>

How long does it take to run just the json request?

call apoc.load.jsonParams(uri, options,null)

YIELD value AS listing

return \*

---

<div class="post-metadata">

**Author:** ![AhmedMahfouz](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@AhmedMahfouz](https://community.neo4j.com/u/AhmedMahfouz)\
**Post date:** [November 14, 2022, 3:13pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/4 "2022-11-14T15:13:13Z")

</div>

Thanks for your response  
it takes 5 ms

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 14, 2022, 4:48pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/5 "2022-11-14T16:48:15Z")

</div>

That is very fast. How about you run the following:

```auto
call apoc.load.jsonParams(uri, options,null)
YIELD value AS listing
MERGE (l:Listing{cid:0})

```

I am trying to figure out if it is the parsing of the json? Even so, your path is not complicated, so I can't image it taking that long to pull out the value of 'listing.results[0].listing\_id'. How complicated is the listing json? Can you share it?

---

<div class="post-metadata">

**Author:** ![AhmedMahfouz](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@AhmedMahfouz](https://community.neo4j.com/u/AhmedMahfouz)\
**Post date:** [November 14, 2022, 5:26pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/6 "2022-11-14T17:26:47Z")

</div>

I tried it without apoc by creating variable and works quickly

like that :

```auto
with ['lst_00000355','lst_00000034b965'] as results
UNWIND results as row
MERGE(l:Listing{clid:row})

```

but when I use it with apoc

it becomes too slow

```auto
json sample : {

key1:"some value"

results: [

{

"listing_id" : 'da312312',

"price_id" : 'prc_231451'

}

]

}

```

and I use results only .

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 14, 2022, 6:01pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/7 "2022-11-14T18:01:29Z")

</div>

Something seems very off. I used the apoc method to pull orders from a Shopify site I have and then pull out some data from the response. The json is fairly large and the response was instantaneous.

---

<div class="post-metadata">

**Author:** ![AhmedMahfouz](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@AhmedMahfouz](https://community.neo4j.com/u/AhmedMahfouz)\
**Post date:** [November 14, 2022, 6:05pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/8 "2022-11-14T18:05:39Z")

</div>

can u please show the code of that ?

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 14, 2022, 7:44pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/9 "2022-11-14T19:44:29Z")

</div>

Here it is, but I had to remove my api key information, so you will not be able to call it and get back a response.

```auto
call apoc.load.jsonParams('https://xxxx:@yyyy.myshopify.com/admin/api/2021-01/orders.json?fields=created_at,id,name,note_attributes,line_items,customer,tags,shipping_address,shipping_lines,order_status_url,financial_status,fulfillment_status,note,source_name,total_line_items_price,total_tax,total_price,total_discounts&status=open&financial_status=paid,pending&fulfillment_status=partial,null&limit=250',{},null) yield value
return value.orders[9].order_status_url

```

---

<div class="post-metadata">

**Author:** ![AhmedMahfouz](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@AhmedMahfouz](https://community.neo4j.com/u/AhmedMahfouz)\
**Post date:** [November 14, 2022, 10:29pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/10 "2022-11-14T22:29:51Z")

</div>

Thanks a lot

we solved it by creating **unique constraints** 🙂

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 14, 2022, 10:31pm UTC](https://community.neo4j.com/t/slow-merge-and-match-when-i-use-unwind/58962/11 "2022-11-14T22:31:21Z")

</div>

That would speed up the merge, since it will also create an index.

Great you got it working.
