16 ms·
Guide to running Elasticsearch in production
- harryf 7y agoStruggling to read this ... the domain typo triggering OCD
- StreamBright 7y agoFor a long time, I read articles only in Pocket. The web has become unreadable at this stage. It is a bit funny that it was created to make the distribution of knowledge easier, having readability its primary feature.
- StreamBright 7y agoGreat writeup. I wish there was a search engine built on the top of Riak that has a bit simpler workload distribution.
- statictype 7y agoIs Riak still supported and used? I was under the impression that it’s dead. Is that not the case?
- StreamBright 7y agoIt is community supported so no commercial support. It is used in many services around the globe. https://github.com/basho/riak_core/commits/develop-3.0 https://github.com/basho/riak_core/commits/develop-3.0
- peterwwillis 7y agoThere's really nothing simple about building apps on top of Riak. It's one of those things that seems simple until you use it in production, and then you realize it's a total nightmare and you can't wait to sunset it.
- StreamBright 7y agoWithout details, I am not really sure what you are talking about. Riak is just a key-value store, probably the simplest abstraction to store data. I have put it in production several times and operated it for years. Reliability and performance is just outstanding. Scalability was capping out around 150 nodes in the same cluster.
- troelsSteegin 7y agoI appreciate the systems perspective and find the writeup useful. However, from a production perspective, I think security should be topic one.
- speedplane 7y ago> from a production perspective, I think security should be topic one Two general approaches to security: - Upgrade to a paid Elastic cluster, and use their own feature-full security suite. - Put a reverse proxy server in front of Elastic (like nginx), and configure that to handle security.
- speedgoose 7y agoI was considering to use ElasticSearch to replace my CouchDB indexes that are way too slow, memory hungry, and not optimized. But I read somewhere, can't remember the source, that ElasticSearch doesn't offer any guarantee that all your data will (eventually) be saved or returned when queried. Is that the case?
- AznHisoka 7y agoThe default refresh rate for ES is a minute or so (can’t remember the exact time). This means when you index a document, it won’t be returned when you search for it until a minute later when the index refreshes. But you can certainly change the configuration so it’s practically real-time. There will be some performance hit though.
- heipei 7y agofwiw, the default refresh interval is 1 second. You should manually increase it if your application allows it. For bulk-indexing you can think about disabling it outright. Source: https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-for-indexing-speed.html https://www.elastic.co/guide/en/elasticsearch/reference/curr...
- frant-hartm 7y agoMaybe you are thinking of Aphyr's analysis of elastic search where he showed that Elastic can lose indexed documents during network partitions: https://aphyr.com/posts/323-call-me-maybe-elasticsearch-1-5-0 https://aphyr.com/posts/323-call-me-maybe-elasticsearch-1-5-... That has been done on relatively old version. Elastic documents known (and fixed) issues here https://www.elastic.co/guide/en/elasticsearch/resiliency/current/index.html https://www.elastic.co/guide/en/elasticsearch/resiliency/cur... but I wouldn't trust this to the letter mainly because of their previous handling of such issues. Elastic is great as a search index, not as a primary database.
- speedgoose 7y agoThanks for your clarification. Not using it as a primary database is fine and I understand that it's not designed for that. But I need to trust the results when I query it. Is it designed for fuzzy searches on many documents when missing one or two documents has no consequences or can I trust that I will always retrieve all documents that should match my query ?
- ivan_ah 7y agoDoes anyone have experience running Elasticsearch as a kubernetes deployment? Can you just spin up some big-RAM containers attached to persisted volumes? Elastic Co. seems to have an offering specialized for k8s: https://www.elastic.co/elastic-cloud-kubernetes https://www.elastic.co/elastic-cloud-kubernetes but I can't understand what it does exactly. Our data is not crazy-big and it doesn't need to be super performant, but for operational simplicity I'd like to deploy as part of the production cluster like all our other app containers rather than some "special" type of container.
- kuhsaft 7y agoI found Elastic Cloud on K8s to be the best way to deploy and manage Elastic clusters on Kubernetes so far. https://www.elastic.co/guide/en/cloud-on-k8s/current/index.html https://www.elastic.co/guide/en/cloud-on-k8s/current/index.h...
- kuhsaft 7y agoElastic Cloud on K8s is an operator that uses CRDs to define Elastic resources. The operator manages and deploys the appropriate deployments and statefulsets for the resource. It handles upgrades of the Elastic services as well. The operator pattern creates a more declarative way of provisioning Elastic resources.
- zegl 7y agoYep, I'm running ES in a StatefulSet. It works nicely out of the box using headless Services for node-to-node discovery, and by using a custom preStop hook, to make sure that the cluster wouldn't become RED after the node shuts down.
- tyingq 7y agoDoes it still have the issue of failing "open to the world" if the x-pack trial expires? See: https://discuss.elastic.co/t/ransom-attack-on-elasticsearch-cluster/71310/18 https://discuss.elastic.co/t/ransom-attack-on-elasticsearch-...
- bpicolo 7y agoXpack's basic features come builtin in latest Elasticsearch - trial is for a separate set of features.
- kuhsaft 7y agoX-Pack Auth is now free and included with Elasticsearch.
- FZ1 7y agoAccording to the docs, it's a 30-Day trial: https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-xpack.html https://www.elastic.co/guide/en/elasticsearch/reference/curr... Are these docs out-of-date ? Does anyone know if any features remain after 30 days if you do not subscribe ?
- kuhsaft 7y ago”If you want to try all of the X-Pack features” It’s quite confusing. There are different tiers of X-Pack: https://www.elastic.co/subscriptions https://www.elastic.co/subscriptions The Basic tier, which is free, supports simple username and password authentication.
- FZ1 7y agoYeah, I read this link also - before posting above. There is no 'username' or 'password' term on that page - nor any positive checkmark in any security column for the open-source tier. 'Basic' tier does have 'File and Native Authentication'. But it is far from clear what that means. More importantly, in several different places that _are_ clear about security in the Elastic documentation, it repeatedly says "there is no security", "assume anyone who can reach elastic is a superuser" ... and more ... So if that is not true, the documentation should probably change ...
- winrid 7y agoI have found you need a queue in front of ES for better write reliability, more so than other DBs. The read/aggregation performance is fantastic though. Also, you should know a little about GC tuning too
- petemc_ 7y agoCan I ask how you implemented such a queue?
- winrid 7y agoWe had our own database as a service thing that used ES and MongoDB. All teams used that service. Basically you would define your schema using the Thrift API and the service provided CRUD operations AND aggregations. This was a Java shop. Scaling writes just meant changing that service's implimentation. We wrote them to Mongo and synched them to ES. There are much better ways to do that, but ES would be overloaded w/ just 500 writes a second so it didn't matter.
- igama 7y agoOne way for example would be store all events you want to write to ElasticSearch to a Queue (like rabbit, Kafka, etc) then have a set of workers/importers (this can even be logstash with input from queue and output ES) that read the events from that queue and store them in ES. This way your system becomes a sync, and your system above is not affected if ES becomes slow writing or goes down for a reason. Your events will remain stored in the queue waiting to be processed.
- there_the_and 7y agoUnsecured Elasticsearch servers have been implicated in multiple breaches in recent months [1][2]. Since this post is an "In depth guide to running Elasticsearch in production,” it should prominently include information related to security and configuration. With tools like these where there is a learning curve for new users, security can end up treated as an afterthought, leading to these kinds of breaches. 1. https://www.pandasecurity.com/mediacenter/news/billion-consumers-data-breach-elasticsearch/ https://www.pandasecurity.com/mediacenter/news/billion-consu... 2. https://thedefenceworks.com/blog/250-million-microsoft-records-exposed-in-another-elasticsearch-server-related-breach/ https://thedefenceworks.com/blog/250-million-microsoft-recor... Edited for clarity
- cloakandswagger 7y agoThis guide is clearly intended to focus on the ops-side of ElasticSearch. No one is being irresponsible, you're basically just complaining that the article was written about one topic instead of another. Notice how it also doesn't talk about system architecture, load balancers, disaster recovery, etc? It's because the author chose to focus the post on cluster configuration. The topic of security could be its own standalone writeup and I highly doubt that its omission is an endorsement for running an ES cluster totally exposed and unsecured.
- tmpz22 7y agoThe argument is that you can't have an in-depth production guide to Elasticsearch without a section on security. "Production" should be "secure". A better title would be "optimizing Elasticsearch performance in production" or something of the sort.
- isbvhodnvemrwvn 7y agoTo be honest I think if you're responsible for running production systems, it would be a no-brainer to run everything as closed up as it gets, with only access from servers which actually need it.
- andrewflnr 7y agoThis was a really helpful article for understanding the architecture of Elasticsearch. However, what I really want to know is why Elastic has the reputation of crapping itself for no reason and what can be done about it.
- arwhatever 7y agoIt seems like most articles discussing Elastic search administration read like an instruction manual for something like steam locomotive - describing just how to constantly shovel the coal in, relieving the steam pressure in just the right way, etc.
- LordHumungous 7y agoGood summary. I recently did this and had to figure this all out by trial and error.
- animalnewbie 7y agoIs there a non-Java alternative to this ES/Logstash stuff? Preferably rust or a native lang, but okay with CLR too. I'm not comfortable running Java in production after previous memory issues...
- rjkennedy98 7y agoMarkLogic is an alternative, but it isn't free.
- BossingAround 7y agoYou should give it another try. New versions of Java have made great progress in the memory area. I feel like a lot of hate Java gets nowadays is largely due to historical reasons. Though come to think of it, if you're talking about ES itself and not Java, then I have no idea, I never used ES in prod.
- speedplane 7y ago> New versions of Java have made great progress in the memory area. Elastic uses huge amounts of memory (30GB is the norm). That's not a problem by itself, but Java garbage collections at this size can often take 10 seconds or more to complete on modern hardware. During this time, the server is basically down, the only solution is to increase timeouts or use replication servers.
- sgift 7y ago> but Java garbage collections at this size can often take 10 seconds or more to complete on modern hardware. For heaps of this size you can use Shenandoah GC and you get pauses well below 100ms. Your post is a perfect example of the type of 'historical reasons' (or historic FUD) the GP talks about.
- speedplane 7y ago> For heaps of this size you can use Shenandoah GC and you get pauses well below 100ms. Your post is a perfect example of the type of 'historical reasons' (or historic FUD) the GP talks about. This GC is relatively new, and Elasticsearch doesn't support it (https://discuss.elastic.co/t/support-for-shenandoah-gc/162378 https://discuss.elastic.co/t/support-for-shenandoah-gc/16237...) It may be a potential solution, but it's hardly a proven one. The concern is not FUD, it's legitimate.
- DmitryOlshansky 7y agoMostly good stuff but a few comments: - article doesn’t clarify if it’s on hardware or VMs - 140 shards per node is certainly on the low side, one can easily scale to 500+ per node (if most shards are small, typically power law distribution) - more RAM is better, and there is a ratio of disk:ram that you need to keep in mind (30-40 for hot data, 200-300 for warm data) - heaps beyond 32g can be beneficial but you’d have to go for 64g+, 32-48g is a dead zone - not a single line about GC tuning (I find default CMS to be quite horrible even in recommended ~31g sizes) - CPUs are often a bottleneck when using SSD drives
- detaro 7y ago> - heaps beyond 32g can be beneficial but you’d have to go for 64g+, 32-48g is a dead zone I'm curious why that is the case?
- wolf550e 7y agoIf the heap is under 32GB, the JVM can use "compressed oops" with 4 byte "pointers" to 8 byte offsets inside the 32GB heap instead of 8 byte pointers. This makes everything more compact. Since Java doesn't have structs, everything is a pointer and arrays of things are arrays of pointers. So a 48GB heap won't fit a lot more data than a 32GB heap. See https://shipilev.net/jvm/anatomy-quarks/23-compressed-references/ https://shipilev.net/jvm/anatomy-quarks/23-compressed-refere... https://wiki.openjdk.java.net/display/HotSpot/CompressedOops https://wiki.openjdk.java.net/display/HotSpot/CompressedOops
- DmitryOlshansky 7y agoJava compressed object pointers. Shipilev (JVM performance engineer) explains it in great detail here: https://shipilev.net/jvm/anatomy-quarks/23-compressed-references/ https://shipilev.net/jvm/anatomy-quarks/23-compressed-refere... But the short of it: Java uses 32-bit numbers for object references if it can address whole heap with it. Given default 8-byte alignment of object we have 2^32 * 8 = 32g of addressable heap. Once we are beyond that number 64-bit references are used and suddenly we are wasting a lot of heap space (Java is very much objects everywhere). Usually up to around 40% of heap is references.
- liveoneggs 7y agoI prefer solr
- rcarmo 7y ago1) Firewall it before anything else. The rest is pretty much common sense for anyone used to run Solr and other indexers in production, but I've always been somewhat amazed at finding default setups insecure (a situation that was still largely true when I looked in-depth at the Python clients last year), which is madness considering that the security (authentication, authorization and auditing) docs are pretty good. So making sure it's only accessible to either localhost or a restricted subnet _when you install it_ seems like the minimum sane thing every sysadmin ought to do by default. Maybe nobody actually reads the docs... (edit: typos)
- testplzignore 7y ago> every document you put into ES will create a segment with only that single document That's not correct. A new segment is created (or rather, made immutable) after a commit. Creating a new segment for every document is a surefire way to kill performance.
- shreyshrey 7y agoFor ES and solr gurus here what is the recommended max size for documents if you want to index lot of office documents?
- itronitron 7y agoWhatever makes sense to your users for their search results. Do they want to get back the whole document or just the relevant parts? If there are separate sections in the office documents that you can pull out and index as separate fields then you should do that. For example, if you were indexing patents, you would want to index abstracts and claims into separate fields.
- shreyshrey 7y agoJust relevant parts. ES says their max size is 100 mb. We have a real life scenario where we want to index millions of office documents to find PII/PHI What is the realistic expectation here. Should we say 50 mb. How everybody else do?
- itronitron 7y agoNot sure about ES, but Solr removed it's max field limit in release 4.0. Text documents tend to be a lot smaller than people expect, both in terms of word count and file size. I think you will be fine with 50 mb if you are using ES.
- inertiatic 7y agoThe text you display back to your user doesn't/shouldn't have to depend on what you index in your information retrieval system. At my last job, we used to index large documents on Solr. The largest chunks of them were indexed in non-stored fields. Which means they were searchable but you couldn't retrieve the actual text. This drastically cut down on the index size and the resources we needed to support it. Then after scoring you'd return the top hits to the main application as IDs, which could retrieve everything needed (full text included) along with all the other information they'd retrieve for the document and generate the actual output.
- hghhbvv 7y agoVespa.ai a good replacement for ES, right?
- pmarreck 7y agoI recently built a webapp and tried to avoid using ES by using Postgres fulltext search and it’s working great so far
- mychael 7y agoIs there a guide for deploying ES on K8S?
- amtux 7y agoFor kubes you could use the helm chart they provide and tune it similarly. https://github.com/elastic/helm-charts/tree/master/elasticsearch https://github.com/elastic/helm-charts/tree/master/elasticse...
- manigandham 7y agoElastic just released their operator called Elastic Cloud on Kubernetes (ECK): https://www.elastic.co/blog/elastic-cloud-on-kubernetes-ECK-is-now-generally-available https://www.elastic.co/blog/elastic-cloud-on-kubernetes-ECK-... Operators are basically mini-programs that run in your K8S cluster and automatically handle deployment, upgrades and maintenance for their specific software. This operator can setup all of the ELK stack and it's all done through custom resource definitions. Use this instead of the helm charts and manual YAML files.
- chx 7y agoIf you secure your Elasticsearch cluster without paying and want to test your queries, it seems to me there are three ways: command line, Deja Vu, Elasticsearch Head extension and if you try to use the Elasticsearch Head extension you will run into https://github.com/mobz/elasticsearch-head/issues/431 https://github.com/mobz/elasticsearch-head/issues/431 Overall, security became free only last year https://www.elastic.co/blog/security-for-elasticsearch-is-now-free https://www.elastic.co/blog/security-for-elasticsearch-is-no... and knowledge and tooling is thin on the ground.
- ram_rar 7y agoWe used to use ElasticSearch a lot for log aggregations. Its a beast of its own. you still need a dedicated team to handle this. Eventually moved to Splunk, wavefront like solutions. It ll costs a lot lesser and frees up engineering time to build a better product.
- thickice 7y agoGenuine questions as someone with no experience in dealing with large sclae log aggregation: Can you share some details on what kind of issues you ran into in production with Elastic Search that needed a dedicated team to manage ?
- m1keil 7y agorelated to this: anyone can share practical advice when it comes to running Elasticsearch for application and infrastructure log aggregation? We started from using Elastic Cloud which is nice enough and saves us the time to initial configuration. However I'm still unsure if the choices I made are the right way to go when designing the indexes.
- jugg1es 7y agoGreat to read from someone who knows it so deeply.
- speedplane 7y ago> Great to read from someone who knows it so deeply. I'd say it's a decent read on Elasticsearch tuning at the intermediate level, but not enough to really get high performance from Elastic. One of the problems with Elastic tuning is that the tuning parameters depend deeply on the type of data you're indexing. Indexing text is far different than indexing numbers or dates. A mapping with a large number of fields will behave differently than with just a few. Some datasets can easily be split up into different indexes, and others are cannot be. To really get the most from Elasticsearch, you have to know what it's doing under-the-hood, and how that maps on to your data. Elasticsearch hides so much complexity (generally a good thing), but unfortunately, it can be difficult to know where the bottlenecks are.
- gui77aume 7y agoIs it ok to have two nodes (mdi) ? Or does 2n+1 means you always want a odd number of master eligible nodes?
- eindiran 7y agoCan someone with experience with multiple indices comment on the relative advantages and disadvantages of running each of the major ones in production: - Elastic - Lucene - Solr - CouchDB - Any other ones I'm unfamiliar with
- mrwnmonm 7y agoCan anyone provide rough numbers about how a million documents with normal queries on it would cost?
- igama 7y agoNo one can answer that for you, you need to test it out your self. Depends on size of documents, number of keys, volume of reads, etc etc. Spin up 1 instance and test it out ;)