{"id":44,"date":"2015-02-20T19:45:01","date_gmt":"2015-02-20T19:45:01","guid":{"rendered":"http:\/\/svops.com\/blog\/?p=44"},"modified":"2015-08-28T20:29:59","modified_gmt":"2015-08-28T20:29:59","slug":"elasticsearch-best-practices","status":"publish","type":"post","link":"http:\/\/svops.com\/blog\/elasticsearch-best-practices\/","title":{"rendered":"Elasticsearch best practices"},"content":{"rendered":"<p>Don&#8217;t forget to check out the <a title=\"logstash best practices\" href=\"http:\/\/svops.com\/blog\/elasticsearch-best-practices\/%20\">Logstash best practices<\/a>, too.<\/p>\n<h2>Memory<\/h2>\n<p>Give elasticsearch half of your system&#8217;s RAM, up to 32GB.<\/p>\n<p>Make sure the allocated memory doesn&#8217;t get swapped out by using mlockall. \u00a0In your config\/elasticsearch.yml, add:<\/p>\n<pre><span style=\"color: #444444; line-height: 1.7;\">bootstrap.mlockall: true<\/span><\/pre>\n<p><span style=\"color: #444444; line-height: 1.7;\">You may need to allow this as part of the startup by running<\/span><\/p>\n<pre>ulimit -l unlimited<\/pre>\n<p>On (at least) centos6, you can have this run for you in the init.d script by adding this line to \/etc\/sysconfig\/elasticsearch:<\/p>\n<pre><span style=\"color: #444444; line-height: 1.7;\">MAX_LOCKED_MEMORY=unlimited<\/span><\/pre>\n<p>For centos7, edit\u00a0\/usr\/lib\/systemd\/system\/elasticsearch.service:<\/p>\n<pre>LimitMEMLOCK=infinity<\/pre>\n<p>After restarting, confirm the setting is correct in elasticsearch:<\/p>\n<pre class=\"programlisting prettyprint lang-sh\"><span class=\"pln\">curl http<\/span><span class=\"pun\">:\/\/<\/span><span class=\"pln\">localhost<\/span><span class=\"pun\">:<\/span><span class=\"lit\">9200<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">_nodes<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">process<\/span><span class=\"pun\">?<\/span><span class=\"pln\">pretty<\/span><\/pre>\n<h2>Index Names<\/h2>\n<p>Use an index for each day. \u00a0There are only two ways to delete data in elasticsearch, and using curator against daily indexes is the right one.<\/p>\n<p>Note that this is the default from logstash.<\/p>\n<h2>Run an odd number of nodes<\/h2>\n<p>This will prevent the split-brain problem.<\/p>\n<h2>Run at least three nodes<\/h2>\n<p>With one replica (two copies), using three nodes will give you an I\/O boost.<\/p>\n<h2>Adjust the Mapping<\/h2>\n<p>Elasticsearch supports many different field types, and you should use the appropriate one for each field.<\/p>\n<p>By using &#8216;int&#8217;, you can use comparisons (&#8220;http_status:&gt;500&#8221;) or ranges (&#8220;http_status:[400 TO 499]&#8221;). \u00a0Other field types give similar benefits of just using strings.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Don&#8217;t forget to check out the Logstash best practices, too. Memory Give elasticsearch half of your system&#8217;s RAM, up to 32GB. Make sure the allocated memory doesn&#8217;t get swapped out by using mlockall. \u00a0In your config\/elasticsearch.yml, add: bootstrap.mlockall: true You &hellip; <a href=\"http:\/\/svops.com\/blog\/elasticsearch-best-practices\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/posts\/44"}],"collection":[{"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/comments?post=44"}],"version-history":[{"count":5,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions"}],"predecessor-version":[{"id":137,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/posts\/44\/revisions\/137"}],"wp:attachment":[{"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/media?parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/categories?post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/svops.com\/blog\/wp-json\/wp\/v2\/tags?post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}