---
# System prepended metadata

title: 'Elasticsearch Best Practices:'

---

Elasticsearch Best Practices:
===

## Checkout ES result Ranking API: 
-  https://www.pragmalingu.de/docs/guides/ranking-api/
-  https://www.youtube.com/watch?v=6ShIMvS7bh0


## Prep for sizing using Simulation
- Use the right data tier: https://www.elastic.co/guide/en/elasticsearch/reference/8.4/data-tiers.html
- Stress testing: Create an Elasticsearch cluster and serve it at roughly the same data rate as expected in a production environment
- Start big and scale down as need during simulation.

## Structure Data in Elasticsearch Indices
-  Index conflict: 
    - Create index mapping to avoid data types conflicts. Data with Similar strucuture  can impact ES search capabily. 
    - to improve the accuracy and flexibility of search queries
- Frozen indices:
    - Free memory for indices not used.
    - Frozen indices becomes read-only, and its resources are no longer active.
    -  Frozen indice, affect performance.
    - Let ES knows, you are search on frozen indices.


    
## Take regular backup snapshots. 
- Back up for disaster recovery. 
- Use snapshot and restore and save them.
- Application consistence, resource efficient as each snapshot are created incrementaly.
        

## Thread Pools Optimization:
- High queues are big problem.
- You can track request queues using the property threadpool.bulk.queue_size. This tells Elasticsearch how many shard requests can be queued to run on the node if there are no threads available to process the request. When the number of tasks exceeds this value, a RemoteTransportException is thrown. Make sure to handle this exception in your code


## Enabling TLS Encryption
-  If encryption is not on, ES will send the data in plain text that can be seized and read by a man in the middle attack.
-  Data that may contain sensitive information and credentials like passwords.
-  Enable TLS for all production environments. This ensures Elasticsearch nodes must use a certificate from a specified certificate authority (CA) when communicating with each other. Each node must identify itself and cannot access the cluster without a valid certificate