Set heap size and limits
diff --git a/elasticsearch/files/elasticsearch b/elasticsearch/files/elasticsearch
new file mode 100644
index 0000000..b951003
--- /dev/null
+++ b/elasticsearch/files/elasticsearch
@@ -0,0 +1,76 @@
+{%- from "elasticsearch/map.jinja" import server with context -%}
+################################
+# Elasticsearch
+################################
+
+# Elasticsearch home directory
+#ES_HOME=/usr/share/elasticsearch
+
+# Elasticsearch configuration directory
+#CONF_DIR=/etc/elasticsearch
+
+# Elasticsearch data directory
+#DATA_DIR=/var/lib/elasticsearch
+
+# Elasticsearch logs directory
+#LOG_DIR=/var/log/elasticsearch
+
+# Elasticsearch PID directory
+#PID_DIR=/var/run/elasticsearch
+
+# Heap size defaults to 256m min, 1g max
+# Set ES_HEAP_SIZE to 50% of available RAM, but no more than 31g
+ES_HEAP_SIZE={{ server.get('heap', {}).get('size', grains.get('mem_total', 1024)/2/1024)|round(0, 'ceil')|int }}g
+
+# Heap new generation
+#ES_HEAP_NEWSIZE=
+
+# Maximum direct memory
+#ES_DIRECT_SIZE=
+
+# Additional Java OPTS
+#ES_JAVA_OPTS=
+
+# Configure restart on package upgrade (true, every other setting will lead to not restarting)
+#ES_RESTART_ON_UPGRADE=true
+
+# Path to the GC log file
+#ES_GC_LOG_FILE=/var/log/elasticsearch/gc.log
+
+################################
+# Elasticsearch service
+################################
+
+# SysV init.d
+#
+# When executing the init script, this user will be used to run the elasticsearch service.
+# The default value is 'elasticsearch' and is declared in the init.d file.
+# Note that this setting is only used by the init script. If changed, make sure that
+# the configured user can read and write into the data, work, plugins and log directories.
+# For systemd service, the user is usually configured in file /usr/lib/systemd/system/elasticsearch.service
+#ES_USER=elasticsearch
+#ES_GROUP=elasticsearch
+
+# The number of seconds to wait before checking if Elasticsearch started successfully as a daemon process
+ES_STARTUP_SLEEP_TIME=5
+
+################################
+# System properties
+################################
+
+# Specifies the maximum file descriptor number that can be opened by this process
+# When using Systemd, this setting is ignored and the LimitNOFILE defined in
+# /usr/lib/systemd/system/elasticsearch.service takes precedence
+MAX_OPEN_FILES=131070
+
+# The maximum number of bytes of memory that may be locked into RAM
+# Set to "unlimited" if you use the 'bootstrap.mlockall: true' option
+# in elasticsearch.yml (ES_HEAP_SIZE  must also be set).
+# When using Systemd, the LimitMEMLOCK property must be set
+# in /usr/lib/systemd/system/elasticsearch.service
+MAX_LOCKED_MEMORY=unlimited
+
+# Maximum number of VMA (Virtual Memory Areas) a process can own
+# When using Systemd, this setting is ignored and the 'vm.max_map_count'
+# property is set at boot time in /usr/lib/sysctl.d/elasticsearch.conf
+#MAX_MAP_COUNT=262144
diff --git a/elasticsearch/server.sls b/elasticsearch/server.sls
index a074d01..ea392ad 100644
--- a/elasticsearch/server.sls
+++ b/elasticsearch/server.sls
@@ -8,6 +8,14 @@
   pkg.installed:
   - names: {{ server.pkgs }}
 
+elasticsearch_default:
+  file.managed:
+  - name: /etc/default/elasticsearch
+  - source: salt://elasticsearch/files/elasticsearch
+  - template: jinja
+  - require:
+    - pkg: elasticsearch_packages
+
 elasticsearch_config:
   file.managed:
   - name: /etc/elasticsearch/elasticsearch.yml
@@ -22,5 +30,6 @@
   - name: {{ server.service }}
   - watch:
     - file: elasticsearch_config
+    - file: elasticsearch_default
 
-{%- endif %}
\ No newline at end of file
+{%- endif %}