Preface
Welcome to the ElasticSearch Server book. While reading this book, you will be taken on a journey to the wonderful world of full-text search provided by ElasticSearch enterprise search server. We will start with a general introduction to ElasticSearch, which covers how to start and run ElasticSearch and how to configure it using both configuration files and the REST API. You will also learn how to create your index structure and tell ElasticSearch about it, how to configure different analyses for fields, and how to use the built-in data types.
This book will also discuss the query language, the so-called Query DSL, that allows you to create complicated queries and filter returned results. In addition to all that, you'll see how you can use faceting to calculate aggregated data based on the results returned by your queries. We will implement the autocomplete functionality together and will learn how to use ElasticSearch's spatial capabilities and how to use prospective search.
Finally, this book will show you some capabilities of the ElasticSearch administration API, with features such as shard placement control, cluster handling, and more. In addition to all that, you'll learn how to overcome some common problems that can come up on your journey with ElasticSearch server.
What this book covers
Chapter 1, Getting Started with ElasticSearch Cluster, covers ElasticSearch installation and configuration, REST API usage, mapping configuration, routing, and index aliasing.
Chapter 2, Searching Your Data, discusses Query DSL—basic and compound queries, filtering, result sorting, and using scripts.
Chapter 3, Extending Your Structure and Search, explains how to index data that is not flat, how to handle highlighting and autocomplete, and how to extend your index with things such as time to live, source, and so on.
Chapter 4, Make Your Search Better, covers how to influence your scoring, how to use synonyms, and how to handle multilingual data. In addition to that, it describes how to use position-aware queries and check why your document was matched.
Chapter 5, Combining Indexing, Analysis, and Search, shows you how to index tree-like structures, use nested objects, handle parent-child relationships, modify your live index structure, fetch data from external systems, and speed up your indexing by using batch processing.
Chapter 6, Beyond Searching, is dedicated to faceting, "more like this", and the prospective search functionality.
Chapter 7, Administrating Your Cluster, is concentrated on the cluster administration API and cluster monitoring. In this chapter you'll also find information about external plugin installation.
Chapter 8, Dealing with Problems, will guide you through fetching large results sets efficiently, controlling cluster rebalancing, validating your queries, and using warm-up queries.
What you need for this book
This book was written using ElasticSearch server 0.20.0, and all the examples and functions should work with it. In addition to that, you'll need a command that allows sending HTTP requests such as curl
, which is available for most operating systems. Please note that all examples in this book use the mentioned curl
tool. If you want to use another tool, please remember to format the request in an appropriate way that is understood by the tool of your choice.
In addition to that, some chapters may require additional software, such as ElasticSearch plugins or MongoDB NoSQL database, but when needed this is explicitly mentioned.
Who this book is for
If you are a beginner to the work of full-text search and ElasticSearch server, this book is especially for you. You will be guided through the basics of ElasticSearch, and you will learn how to use some of the advanced functionalities.
If you know ElasticSearch and have worked with it, you may find this book interesting as it provides a good overview of all the functionalities with examples and descriptions. However, you may encounter sections that you already know about.
If you know the Apache Solr search engine, this book can also be used to compare some functionalities of Apache Solr and ElasticSearch. This may help you judge which tool is more appropriate for your use case.
If you know all the details about ElasticSearch and know how each of the configuration parameters works, this is definitely not the book you are looking for!
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text are shown as follows: "The indices
object contains information about library
and map
indices. The primaries
object contains information about all primary shards allocated on the current node."
A block of code is set as follows:
"store" : { "size" : "7.6kb", "size_in_bytes" : 7867, "throttle_time" : "0s", "throttle_time_in_millis" : 0 }
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
public class HashCodeSortScript extends AbstractSearchScript {
private String field = "name";
public HashCodeSortScript(Map<String, Object> params)
Any command-line input or output is written as follows:
curl -XPOST 'localhost:9200/_cluster/reroute' -d '{ "commands" : [ {"move" : {"index" : "shop", "shard" : 1, "from_node" : "es_node_one", "to_node" : "es_node_two"}}, {"cancel" : {"index" : "shop", "shard" : 0, "node" : "es_node_one"}}
New terms and important words are shown in bold.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to <feedback@packtpub.com>
, and mention the book title through the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.
Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
Questions
You can contact us at <questions@packtpub.com>
if you are having a problem with any aspect of the book, and we will do our best to address it.