# Segments memory increases after search

**URL:** https://discuss.elastic.co/t/segments-memory-increases-after-search/33633
**Category:** Elasticsearch
**Created:** [November 3, 2015, 1:22pm UTC](https://discuss.elastic.co/t/segments-memory-increases-after-search/33633 "2015-11-03T13:22:47Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_F](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Alex\_F](https://discuss.elastic.co/u/Alex_F)
#### Post date: [November 3, 2015, 1:22pm UTC](https://discuss.elastic.co/t/segments-memory-increases-after-search/33633/1 "2015-11-03T13:22:47Z")

</div>

Hello everyone!

Does anybody know why segments memory increases (column 'sm' in \_cat API) after searches.  
For example, I have the next stat before searches:  
`n hp hm fm fe fcm sm so sqc`  
`Thunderstrike 58 86gb 0b 26575 1.7gb 29.9gb 0 0`  
`Burstarr 57 86gb 492.4mb 20461 1.4gb 24.9gb 0 0`  
`Microchip 2 16gb 0b 0 0b 0b 0 0`

And after ~30 wide searches:  
`n hp hm fm fe fcm sm so sqc`  
`Thunderstrike 72 86gb 5.1gb 139468 1.7gb 44.9gb 0 0`  
`Burstarr 78 86gb 2.8gb 78926 1.4gb 37.4gb 0 0`  
`Microchip 10 16gb 0b 0 0b 0b 0 0`

If I restart cluster, I'll get the first values of sm.  
Is it Lucene area?

P.S. Yes, I have a LOT of data (~10TB of indices size).

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [November 3, 2015, 1:41pm UTC](https://discuss.elastic.co/t/segments-memory-increases-after-search/33633/2 "2015-11-03T13:41:35Z")

</div>

Its super hard to say but I have a few tips:

1. Wrap the output of `_cat` in triple backticks (```) so it gets a fixed width font.
2. Post an example query. Or one with names changed but the same structure.

---

<div class="post-metadata">

### Author: ![Alex\_F](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Alex\_F](https://discuss.elastic.co/u/Alex_F)
#### Post date: [November 3, 2015, 2:18pm UTC](https://discuss.elastic.co/t/segments-memory-increases-after-search/33633/3 "2015-11-03T14:18:31Z")

</div>

Thanks for your reply, Nik! I have the same template for all search queries:

```auto
    "from" : 0,
    "size" : 100,
    "query" : {
        "filtered" : {
            "query" : {
                "indices" : {
                    "indices" : ["2015-*"],
                    "query" : {
                        "bool" : {
                            "must" : [
                                {
                                    "query_string" : {
                                        "default_operator" : "AND",
                                        "query" : "keyword"
                                    }
                                }
                            ]
                        }
                    },
                    "no_match_query" : "none"
                }
            },
            "filter" : {
                "and" : [
                    {
                        "numeric_range" : {
                            "73" : { "from" : 0, "to" : 2067935475, "include_lower" : true, "include_upper" : true }
                         }
                    }
                 ]
            }
        }
    },
    "partial_fields" : {
        "_source" : {
            "exclude" : "12290"
        }
    }
}

```

Also, I'm using elasticsearch 1.3.9, but I saw the same behaviour with 1.7.3.

---

<div class="post-metadata">

### Author: ![Alex\_F](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Alex\_F](https://discuss.elastic.co/u/Alex_F)
#### Post date: [December 15, 2015, 9:05am UTC](https://discuss.elastic.co/t/segments-memory-increases-after-search/33633/4 "2015-12-15T09:05:40Z")

</div>

I can add some additional information I investigated recently.

````auto
elasticsearch-1.7.3-1.noarch
[localhost-"192.168.238.168" index]# service elasticsearch restart
Stopping elasticsearch: [OK]
Starting elasticsearch: [OK]
[localhost-"192.168.238.168" index]# curl '127.0.0.1:9200/_cat/nodes?h=sm&v'
  sm 
34mb
[localhost-"192.168.238.168" index]# curl localhost:9200/_search?q=hello
{result}
[localhost-"192.168.238.168" index]# curl '127.0.0.1:9200/_cat/nodes?h=sm&v'
    sm 
44.8mb
[localhost-"192.168.238.168" index]# service elasticsearch restart
Stopping elasticsearch: [OK]
Starting elasticsearch: [OK]
[localhost-"192.168.238.168" index]# curl '127.0.0.1:9200/_cat/nodes?h=sm&v'
  sm 
34mb```

But!

```[localhost-"192.168.238.168" index]# service elasticsearch restart
Stopping elasticsearch: [OK]
Starting elasticsearch: [OK]
[localhost-"192.168.238.168" index]# curl '127.0.0.1:9200/_cat/nodes?h=sm&v'
  sm 
34mb
[localhost-"192.168.238.168" index]# curl localhost:9200/_search?q=h*
{result}
[localhost-"192.168.238.168" index]# curl '127.0.0.1:9200/_cat/nodes?h=sm&v'
  sm 
34mb```

So sm increases after full term search.

I investigated lucene code a bit and found that sm consists of FieldsProducer, DocValuesProducer, StoredFieldsReader and TermVectorsReader. Who is the culprit? TermsVector?

Is it important? Very important (at least for me), because I have the next typical situation:
1) After ES starting everything is OK, GC works rarely and frees a lot of memory;
```[2015-12-13 14:00:09,446][INFO][monitor.jvm] [Sluk] [gc][young][37410][451] duration [863ms], collections [1]/[1s], total [863ms]/[1.1m], memory [76.8gb]->[53.5gb]/
[86gb], all_pools {[young] [26.2gb]->[32mb]/[0b]}{[survivor] [352mb]->[3.2gb]/[0b]}{[old] [50.2gb]->[50.2gb]/[86gb]}```
2) I make 100 searches or more
3) GC works every minute and frees nothing
```[2015-12-15 14:02:20,000][WARN][monitor.jvm] [War V] [gc][old][15560][682] duration [25.9s], collections [1]/[30.2s], total [25.9s]/[5.1h], memory [80.2gb]->[77.8gb
]/[86gb], all_pools {[young] [2gb]->[128mb]/[0b]}{[survivor] [192mb]->[0b]/[0b]}{[old] [78gb]->[77.7gb]/[86gb]}```
4) ES becomes unresponsive

But index size the same!
````

---

<div class="post-metadata">

### Author: ![Alex\_F](https://avatars.discourse-cdn.com/v4/letter/a/b77776/32.png) [@Alex\_F](https://discuss.elastic.co/u/Alex_F)
#### Post date: [December 17, 2015, 9:03am UTC](https://discuss.elastic.co/t/segments-memory-increases-after-search/33633/5 "2015-12-17T09:03:28Z")

</div>

So it were norms and I chose a hard way to realize that 🙂 Disabling norms helped me.

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [December 17, 2015, 2:13pm UTC](https://discuss.elastic.co/t/segments-memory-increases-after-search/33633/6 "2015-12-17T14:13:51Z")

</div>

> [@Alex\_F](#):
>
> So it were norms and I chose a hard way to realize that 😄 Disabling norms helped me.

Sorry! Yeah, norms are a thing. They live in memory in some versions but there was an effort to get them to disk like doc values and that's done but I don't remember which version it is in. 2.0 probably.

---

<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: [July 5, 2017, 11:30pm UTC](https://discuss.elastic.co/t/segments-memory-increases-after-search/33633/7 "2017-07-05T23:30:11Z")

</div>


