having index types with different mappings allows you to organize different
data types, data sources, or different data models in a single index.
Imagine building a library: a library has books, serials, but also CD or
DVD, or even full-text files online, all in different languages, and all
have different media identifier numbers (ISBN/EAN, ISSN, CD-Item-No/UPCs,
The challenge is to build a single index with the media stock item number
as the primary key and with the different media identifiers in an
identifier field with a comfortable identifier search.
Instead of creating different identifier field types in each document
class, like you would probably do in a relational database world, you can
create different index types in Elasticsearch and put the identifier
numbers in a commonly named field "identifier". This is the power of
"mapping" in Elasticsearch.
As an example, let's assume three different identifier types. Books have
ISBN/EAN, CDs have UPCs, and online videos have URLs.
index/type/id = library/books/1
"identifier" : "978-1-933988-17-7"
index/type/id = library/cds/2
"title" : "The first CD ever",
"identifier" : "042280001124"
index/type/id = library/videos/3
"creator" : "Simon Willnauer",
"title" : "Lucene 4 Performance Tuning",
"identifier" : "http://vimeo.com/55163540"
Assume you have many analyzers in the Elasticsearch mapping plus other
methods to process such identifiers accordingly to their type (for example,
auto-adding tags for the ID scheme, removing hyphens from ISBNs, extracting
IDs from video URLs, looking up persistent identifiers, whatever), the
advantage should be obvious.
Later while searching, you can direct your search client to the index
"library", and all searches to the "identifier" field will be mapped
correctly to the effective mapping of the underlying identifier field.
You can even arrange searches to different objects in different index types.
And this approach scales. Adding a new media type to the library is easy.
Just add a new index type, set up new analyzers in the mapping, and you're
So, a type is not just a table in the sense of a relational database, it is
more like a virtual table or a materialized view.
Index types can also be organized by custom demand. In a scientific article
database, you want to add articles, but on different academic subjects or
field of studies. Scientists like to perform limited searches within
contributions in their field without using facets, but if you ask them more
firmly, they also want to search in all articles. Now, you could add a
custom field to your documents, or you could instrument Elasticsearch and
create index types for each field of stud. A search UI can direct the field
of study to the index type much more elegant by REST addressing than
managing an optional filter term in the query to select the requested field
Note, internally in a document, you can refer to a field named "_type",
because under the hood, Elasticsearch handles the index type like an
ordinary non-analyzed field. It is just exposed to the API.