So far, we have learned how to use Elasticsearch as a simple NoSQL-style distributed document store. We can throw JSON documents at Elasticsearch and retrieve each one by ID. But the real power of Elasticsearch lies in its ability to make sense out of chaos — to turn Big Data into Big Information.
This is the reason that we use structured JSON documents, rather than amorphous blobs of data. Elasticsearch not only stores the document, but also indexes the content of the document in order to make it searchable.
Every field in a document is indexed and can be queried. And it’s not just that. During a single query, Elasticsearch can use all of these indices, to return results at breath-taking speed. That’s something that you could never consider doing with a traditional database.
A search can be any of the following:
-
A structured query on concrete fields like
gender
orage
, sorted by a field likejoin_date
, similar to the type of query that you could construct in SQL -
A full-text query, which finds all documents matching the search keywords, and returns them sorted by relevance
-
A combination of the two
While many searches will just work out of the box, to use Elasticsearch to its full potential, you need to understand three subjects:
- Mapping
-
How the data in each field is interpreted
- Analysis
-
How full text is processed to make it searchable
- Query DSL
-
The flexible, powerful query language used by Elasticsearch
Each of these is a big subject in its own right, and we explain them in detail in [search-in-depth]. The chapters in this section introduce the basic concepts of all three—just enough to help you to get an overall understanding of how search works.
We will start by explaining the search
API in its simplest form.
The documents that we will use for test purposes in this chapter can be found in this gist: https://gist.github.com/clintongormley/8579281.
You can copy the commands and paste them into your shell in order to follow along with this chapter.
Alternatively, if you’re in the online version of this book, you can click here to open in Sense.