Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Elasticsearch 7.0 Cookbook
Elasticsearch 7.0 Cookbook

Elasticsearch 7.0 Cookbook: Over 100 recipes for fast, scalable, and reliable search for your enterprise , Fourth Edition

eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Elasticsearch 7.0 Cookbook

Mapping base types

Using explicit mapping makes it possible to be faster in starting to ingest the data using a schema-less approach without being concerned about field types. Thus, to achieve better results and performance in indexing, it's required to manually define a mapping.

Fine-tuning mapping brings some advantages, such as the following:

  • Reducing the index size on the disk (disabling functionalities for custom fields)
  • Indexing only interesting fields (general speed up)
  • Precooking data for fast search or real-time analytics (such as facets)
  • Correctly defining whether a field must be analyzed in multiple tokens or considered as a single token

Elasticsearch allows you to use base fields with a wide range of configurations.

Getting ready

...

Mapping arrays

An array or multi-value fields are very common in data models (such as multiple phone numbers, addresses, names, aliases, and so on), but not natively supported in traditional SQL solutions.

In SQL, multi-value fields require the creation of accessory tables that must be joined to gather all the values, leading to poor performance when the cardinality of records is huge.

Elasticsearch, which works natively in JSON, provides support for multi-value fields transparently.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.

To execute these commands, any HTTP client can be used, such as curl (https://curl...

Mapping an object

An object is a base structure (analogous to a record in SQL). Elasticsearch extends the traditional use of objects, thus allowing for recursive embedded objects.

Getting ready

You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.

To execute the commands, any HTTP client can be used such as curl (https://curl.haxx.se/), postman (https://www.getpostman.com/), or similar. Again, I suggest using Kibana console, which provides code completion and better character escaping for Elasticsearch.

How to do it...

...

Mapping a document

The document is also referred to as the root object. This has special parameters that control its behavior, which are mainly used internally to do special processing, such as routing or time-to-live of documents.

In this recipe, we'll take a look at these special fields and learn how to use them.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1Getting Started.

To execute these commands, every HTTP client can be used, such as curl (https://curl.haxx.se/), postman (https://www.getpostman.com/), or similar. I suggest using the Kibana console, which provides code completion and better character escaping...

Using dynamic templates in document mapping

In the Using explicit mapping creation recipe, we have seen how Elasticsearch is able to guess the field type using reflection. In this recipe, we'll see how we can help it improve its guessing capabilities via dynamic templates.

The dynamic template feature is very useful. For example, it may be useful in situations in which you need to create several indices with similar types because it allows you to move the need to define mappings from coded initial routines to automatic index-document creation. A typical usage is to define types for Logstash log indices.

Getting ready

You need an up-and-running Elasticsearch installation as we described in the Downloading and installing...

Managing nested objects

There is a special type of embedded object: the nested one. This resolves a problem related to Lucene indexing architecture, in which all the fields of embedded objects are viewed as a single object. During search, in Lucene, it is not possible to distinguish between values and different embedded objects in the same multi-valued array.

If we consider the previous order example, it's not possible to distinguish an item name and its quantity with the same query, as Lucene puts them in the same Lucene document object. We need to index them in different documents and then join them. This entire trip is managed by nested objects and nested queries.

Getting ready

You need an up-and-running Elasticsearch installation...

Managing a child document with a join field

In the previous recipe, we have seen how it's possible to manage relations between objects with the nested object type. The disadvantage of nested objects is their dependence from their parent. If you need to change a value of a nested object, you need to reindex the parent (this brings a potential performance overhead if the nested objects change too quickly). To solve this problem, Elasticsearch allows you to define child documents.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.

To execute these commands, any HTTP client can be used, such as curl...

Adding a field with multiple mappings

Often a field must be processed with several core types or in different ways. For example, a string field must be processed as tokenized for search and not-tokenized for sorting. To do this, we need to define a fields multifield special property.

The fields property is a very powerful feature of mappings because it allows you to use the same field in different ways.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1Getting Started.

To execute these commands, any HTTP client can be used such as curl (https://curl.haxx.se/), postman (https://www.getpostman.com/), or similar...

Mapping a GeoPoint field

Elasticsearch natively supports the use of geolocation types—special types that allow you to localize your document in geographic coordinates (latitude and longitude) around the world.

There are two main types that are used in the geographic world: the point and the shape. In this recipe, we'll look at GeoPoint—the base element of geo location.

Getting ready

 

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1Getting Started.

To execute these commands, any HTTP client can be used such as curl (https://curl.haxx.se/), postman (https://www.getpostman.com/), or similar. I suggest...

Mapping a GeoShape field

An extension to the concept of point is the shape. Elasticsearch provides a type that facilitates the management of arbitrary polygons in GeoShape.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.

To be able to use advanced shape management, Elasticsearch requires two JAR libraries in its classpath (usually the lib directory), as follows:

  • Spatial4J (v0.3)
  • JTS (v1.13)

How to do it...

To map a geo_shape type, a user must explicitly provide some...

Mapping an IP field

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.

How to do it...

You need to define the type of the field that contains...

Mapping an alias field

It is very common to have a lot of different types in several indices. Because Elasticsearch makes it possible to search in many indices, you should filter for common fields at the same time.

In the real world, these fields are not always called in the same way in all mappings (generally because they are derived from different entities), it's very common to have a mix of added_date, timestamp, @timestamp, and date_add fields that are referring to the same date concept.

The alias fields allow you to define an alias name to be resolved, as well as a query time to simplify the call of all fields with the same meaning.

Getting ready

 

You need an up-and-running Elasticsearch installation...

Mapping a Percolator field

The Percolator is a special type field that makes it possible to store an Elasticsearch query inside the field and use it in percolator query.

The Percolator can be used to detect all queries that match a document.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1Getting Started.

To execute these commands, any HTTP client can be used such as curl (https://curl.haxx.se/), postman (https://www.getpostman.com/), or similar. I suggest using Kibana console, which provides code completion and better character escaping for Elasticsearch.

...

Mapping feature and feature vector fields

It's common to have the requirement to score a document dynamically, depending on the context. For example, scoring more particular documents that are inside a category—the classic scenario is to boost (increase low scored) documents that are based on value such as page rank, hits, or categories.

Elasticsearch 7.x provides two new ways to boost your scores based on values: one is the feature fields and the other is its extension to a vector of values.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1Getting Started.

To execute these commands, any HTTP client...

Adding metadata to a mapping

Sometimes, when we are working with our mapping, it is required to store some additional data to be used for display purposes, ORM facilities, permissions, or simply to track them in the mapping.

Elasticsearch allows you to store every kind of JSON data you want in the mapping with the special _meta field.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.

How to do it...

The _meta mapping field can be populated with any data we want. Consider...

Specifying different analyzers

In the previous recipes, we have looked at how to map different fields and objects in Elasticsearch, and we have described how it's easy to change the standard analyzer with the analyzer and search_analyzer properties.

In this recipe, we will loot at several analyzers and learn how to use them to improve indexing and searching quality.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1Getting Started.

How to do it...

Every core type field allows...

Mapping a completion field

To be able to provide search functionalities for our user, one of the most common requirements is to provide a text suggestion for our query.

Elasticsearch provides a helper for archiving this functionality using a special type mapping called completion.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1Getting Started.

How to do it...

The definition of a completion field is similar to the previous core type fields. For example, to provide a suggestion...

Mapping a GeoPoint field


Elasticsearch natively supports the use of geolocation types—special types that allow you to localize your document in geographic coordinates (latitude and longitude) around the world.

There are two main types that are used in the geographic world: the point and the shape. In this recipe, we'll look at GeoPoint—the base element of geo location.

Getting ready

 

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1Getting Started.

To execute these commands, any HTTP client can be used such as curl (https://curl.haxx.se/), postman (https://www.getpostman.com/), or similar. I suggest using Kibana console, which provides code completion and better character escaping for Elasticsearch.

 

How to do it...

The type of the field must be set to geo_point to define a GeoPoint.

We can extend the order example by adding a new field that stores the location of a customer. This will be the result as follows...

Mapping a GeoShape field


An extension to the concept of point is the shape. Elasticsearch provides a type that facilitates the management of arbitrary polygons in GeoShape.

Getting ready

You need an up-and-running Elasticsearch installation, as we described in the Downloading and installing Elasticsearch recipe in Chapter 1, Getting Started.

To be able to use advanced shape management, Elasticsearch requires two JAR libraries in its classpath (usually the lib directory), as follows:

  • Spatial4J (v0.3)
  • JTS (v1.13)

How to do it...

To map a geo_shape type, a user must explicitly provide some parameters:

  • tree: This is the name of the PrefixTree implementation—geohash for GeohashPrefixTree and quadtree for QuadPrefixTree (geohash default).
  • precision: This is used instead of tree_levels to provide a more human value to be used in the tree level. The precision number can be followed by the unit, that is, 10 m, 10 km, 10 miles, and so on.
  • tree_levels: This is the maximum number of layers to be used in the prefix...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Extend Elasticsearch functionalities and learn how to deploy on Elastic Cloud
  • Deploy and manage simple Elasticsearch nodes as well as complex cluster topologies
  • Explore the capabilities of Elasticsearch 7 with easy-to-follow recipes

Description

Elasticsearch is a Lucene-based distributed search server that allows users to index and search unstructured content with petabytes of data. With this book, you'll be guided through comprehensive recipes on what's new in Elasticsearch 7, and see how to create and run complex queries and analytics. Packed with recipes on performing index mapping, aggregation, and scripting using Elasticsearch, this fourth edition of Elasticsearch Cookbook will get you acquainted with numerous solutions and quick techniques for performing both every day and uncommon tasks such as deploying Elasticsearch nodes, integrating other tools to Elasticsearch, and creating different visualizations. You will install Kibana to monitor a cluster and also extend it using a variety of plugins. Finally, you will integrate your Java, Scala, Python, and big data applications such as Apache Spark and Pig with Elasticsearch, and create efficient data applications powered by enhanced functionalities and custom plugins. By the end of this book, you will have gained in-depth knowledge of implementing Elasticsearch architecture, and you'll be able to manage, search, and store data efficiently and effectively using Elasticsearch.

Who is this book for?

If you’re a software engineer, big data infrastructure engineer, or Elasticsearch developer, you'll find this book useful. This Elasticsearch book will also help data professionals working in the e-commerce and FMCG industry who use Elastic for metrics evaluation and search analytics to get deeper insights for better business decisions. Prior experience with Elasticsearch will help you get the most out of this book.

What you will learn

  • Create an efficient architecture with Elasticsearch
  • Optimize search results by executing analytics aggregations
  • Build complex queries by managing indices and documents
  • Monitor the performance of your cluster and nodes
  • Design advanced mapping to take full control of index steps
  • Integrate Elasticsearch in Java, Scala, Python, and big data applications
  • Install Kibana to monitor clusters and extend it for plugins

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 30, 2019
Length: 724 pages
Edition : 4th
Language : English
ISBN-13 : 9781789959024
Vendor :
Elastic
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 30, 2019
Length: 724 pages
Edition : 4th
Language : English
ISBN-13 : 9781789959024
Vendor :
Elastic
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 112.97
Advanced Elasticsearch 7.0
€41.99
Elasticsearch 7.0 Cookbook
€41.99
Learning Elastic Stack 7.0
€28.99
Total 112.97 Stars icon
Banner background image

Table of Contents

18 Chapters
Getting Started Chevron down icon Chevron up icon
Managing Mapping Chevron down icon Chevron up icon
Basic Operations Chevron down icon Chevron up icon
Exploring Search Capabilities Chevron down icon Chevron up icon
Text and Numeric Queries Chevron down icon Chevron up icon
Relationship and Geo Queries Chevron down icon Chevron up icon
Aggregations Chevron down icon Chevron up icon
Scripting in Elasticsearch Chevron down icon Chevron up icon
Managing Clusters Chevron down icon Chevron up icon
Backups and Restoring Data Chevron down icon Chevron up icon
User Interfaces Chevron down icon Chevron up icon
Using the Ingest Module Chevron down icon Chevron up icon
Java Integration Chevron down icon Chevron up icon
Scala Integration Chevron down icon Chevron up icon
Python Integration Chevron down icon Chevron up icon
Plugin Development Chevron down icon Chevron up icon
Big Data Integration Chevron down icon Chevron up icon
Another Book You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(2 Ratings)
5 star 0%
4 star 100%
3 star 0%
2 star 0%
1 star 0%
bruvio May 02, 2023
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
useful book to navigate ES maze.
Amazon Verified review Amazon
SoftwareGuy Aug 03, 2019
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I like this book and at the time of purchase it was like the only version 7.x available although I have to mention there couple pieces that are wrong. Cluster discovery changed in version 7 yet this book point at the older methods....anyway other than that small hiccup it is good for CCQs and Java HLRC though it doesn’t get super deep.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.