# Problem with very slow insertion

**URL:** <https://discuss.elastic.co/t/problem-with-very-slow-insertion/153732>\
**Category:** Elasticsearch\
**Created:** [October 24, 2018, 7:08am UTC](https://discuss.elastic.co/t/problem-with-very-slow-insertion/153732 "2018-10-24T07:08:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![magorbe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magorbe/32/36871_2.png) [@magorbe](https://discuss.elastic.co/u/magorbe)\
**Post date:** [October 24, 2018, 7:08am UTC](https://discuss.elastic.co/t/problem-with-very-slow-insertion/153732/1 "2018-10-24T07:08:27Z")

</div>

Hi, I'm desperate. I have the following mapping:

```
{
    "my_index": {
        "aliases": {},
        "mappings": {
            "a_c": {
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "s": {
                        "type": "nested",
                        "properties": {
                            "c_r": {
                                "type": "nested",
                                "properties": {
                                    "c": {
                                        "type": "string"
                                    },
                                    "end": {
                                        "type": "long"
                                    },
                                    "id": {
                                        "type": "string"
                                    },
                                    "start": {
                                        "type": "long"
                                    }
                                }
                            },
                            "g": {
                                "type": "string"
                            },
                            "id": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        },
        "settings": {
            "index": {
                "creation_date": "1505476515647",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "_0IiQCPrQ1i-kDP1481y8w",
                "version": {
                    "created": "2030099"
                }
            }
        },
        "warmers": {}
    }
}

```

I try to make an insert of new c\_r inside my elastic, and I do it using a groovy script (my elastic is a version 2), but I have a serious problem: when I have many s's Elastic hangs during insertion. I suspect that my problem is indexing, because the number of c\_r's within the s's is very large. Is there any way to do the insertion avoiding indexing? Neither can I disable the indexes of: "c", "start", "end", because I need them for other searches.

The script is :

```
{"script": " boolean f = false;\nfor (int i = 0; i < ctx._source.s.size(); i++) "
                                "{if (ctx._source.s[i].id == s.id)"
                                " {ctx._source.s[i].covered_region = s.c_r;"
                                "f=true;break;}}\nif(!f){ctx._source.s.add(s);}", "params": params}

```

In params I have a s with a lot of c\_r's

Any ideas? Thanks!!!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [October 24, 2018, 7:18am UTC](https://discuss.elastic.co/t/problem-with-very-slow-insertion/153732/2 "2018-10-24T07:18:22Z")

</div>

When you index or update a document with nested structures, Elasticsearch created multiple documents behind the scenes. For every update (even if just adding one nested component to the document) all of these are reindexed, which means updating documents with a lot of nested components can require a lot of work.

---

<div class="post-metadata">

**Author:** ![magorbe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magorbe/32/36871_2.png) [@magorbe](https://discuss.elastic.co/u/magorbe)\
**Post date:** [October 24, 2018, 7:29am UTC](https://discuss.elastic.co/t/problem-with-very-slow-insertion/153732/3 "2018-10-24T07:29:01Z")

</div>

So if I delete the nested of c\_r ...will I have significant improvement? But, that can bring me performance problems on the other hand? Thanks!

```auto
{
    "my_index": {
        "aliases": {},
        "mappings": {
            "a_c": {
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "s": {
                        "type": "nested",
                        "properties": {
                            "c_r": {
                                "properties": {
                                    "c": {
                                        "type": "string"
                                    },
                                    "end": {
                                        "type": "long"
                                    },
                                    "id": {
                                        "type": "string"
                                    },
                                    "start": {
                                        "type": "long"
                                    }
                                }
                            },
                            "g": {
                                "type": "string"
                            },
                            "id": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        },
        "settings": {
            "index": {
                "creation_date": "1505476515647",
                "number_of_shards": "5",
                "number_of_replicas": "1",
                "uuid": "_0IiQCPrQ1i-kDP1481y8w",
                "version": {
                    "created": "2030099"
                }
            }
        },
        "warmers": {}
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 21, 2018, 7:29am UTC](https://discuss.elastic.co/t/problem-with-very-slow-insertion/153732/4 "2018-11-21T07:29:01Z")

</div>

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