Elastic Search is used as a Search engine in Magento. Starting from Magento 2.4, Elasticsearch is an essential component, and deploying/Installation of Magento without Elasticsearch is not feasible. In this article, we will discuss How to fetch all the indices of Elastic Search and delete Specific indices.
E-commerce developers are constantly striving to integrate technologies and elements that directly enhance user experience, and Magento is no exception. In online stores, customers increasingly utilize concise and intelligent search terms, anticipating swift results tailored to their product queries.
What is Elastic Search and Why it is used in Magento?
Elasticsearch is a robust and scalable open-source search and analytics engine built on top of Apache Lucene. It’s designed to handle a wide range of use cases, from full-text search to real-time analytics and log monitoring. Its speed, scalability, flexibility, and rich feature set make it a popular choice for a wide range of use cases across industries.
Here’s why Elasticsearch is mainly used in Magento:
- Scalability: Elasticsearch is built to scale horizontally, which means you can add more servers to your Elasticsearch cluster to handle mounting data volumes and search traffic. This makes it suitable for both small-scale deployments and large enterprise systems.
- Speed: Elasticsearch is optimized for fast search queries, making it ideal for applications where low latency is crucial. It uses inverted indices and various caching mechanisms to deliver quick and efficient search results.
- Flexibility: Elasticsearch supports both structured and unstructured data, allowing you to index and search JSON documents with ease. It also offers powerful querying capabilities, including full-text search, aggregations, and geospatial queries
- Community and ecosystem: Elasticsearch has a vibrant community and a rich ecosystem of plugins and integrations. This makes it easy to extend and customize Elasticsearch to fit your specific needs
How to fetch all the indices of Elastic Search?
In Magento 2, you have the capability to retrieve a comprehensive roster of all indices accessible within the system. By utilizing the CLI command, you can assess the status of each index employed by the system
You can run the given command:
curl -X GET http://localhost:9200/_cat/indices?v
localhost is the default hostname of Elastic Search if you have changed the hostname then you need to replace it with your actual hostname.
You will get the response looks like below if the valid URL is available:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open magento_default_catalog_product_20230703_022952 bjHqWsUATpGg1xwnnB5YAg 1 0 0 0 283b 283b
With a list of available indices for the system in a response. Health status green displays your indices status is healthy.
How to delete Specific indices from Elasticsearch?
You can delete specific elastic search indices or all the indices using the Delete command. You have the option to execute the provided command in order to delete a particular index from Elasticsearch.
curl -X DELETE 'http://localhost:9200/<index_name>'
Here, index_name is your actual elastic search index name. If you don’t know the index name then you can check it with the command to fetch all the index names from Elasticsearch which has mentioned above in this article.
Delete all indices of elastic search:
You can delete all the indices from Elasticserch with the help of the following command:
curl -X DELETE 'http://localhost:9200/_all'
Once you delete indices run the indexer command Once again to push the data to elastic search indexes.
Keep coding, keep exploring, and may your bytes be ever in your favor! 🌐💻🚀