Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Optimizing an index


The core of ElasticSearch is based on Lucene, which stores the data in segments on the disk. During the life of an Index, a lot of segments are created and changed. With the increase of segment numbers, the speed of search decreases due to the time required to read all of them. The optimize operation allows us to consolidate the index for faster search performance, reducing segments.

Getting ready

You will need a working ElasticSearch cluster and the index created in the Creating an index recipe in this chapter.

How to do it...

The URL format to optimize one or more indices is:

http://<server>/<index_name(s)>/_optimize

The URL format to optimize all the indices in a cluster is:

http://<server>/_optimize

The HTTP method used is POST.

To optimize an index, we will perform the following steps:

  1. If we consider the Index created in the Creating an index recipe, the call will be:

    curl -XPOST 'http://localhost:9200/myindex/_optimize'
    
  2. The result returned by ElasticSearch...