Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

ElasticSearch is one of the most promising NoSQL technologies available and is built to provide a scalable search solution with built-in support for near real-time search and multi-tenancy. This practical guide is a complete reference for using ElasticSearch and covers 360 degrees of the ElasticSearch ecosystem. We will get started by showing you how to choose the correct transport layer, communicate with the server, and create custom internal actions for boosting tailored needs. Starting with the basics of the ElasticSearch architecture and how to efficiently index, search, and execute analytics on it, you will learn how to extend ElasticSearch by scripting and monitoring its behaviour. Step-by-step, this book will help you to improve your ability to manage data in indexing with more tailored mappings, along with searching and executing analytics with facets. The topics explored in the book also cover how to integrate ElasticSearch with Python and Java applications. This comprehensive guide will allow you to master storing, searching, and analyzing data with ElasticSearch.
Table of Contents (19 chapters)
ElasticSearch Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using span queries


The big difference between standard systems (SQL, but also many NoSQL technologies such as MongoDB, Riak, or CouchDB) and ElasticSearch is the number of facilities to express text queries.

The span query family is a group of queries that control a sequence of text tokens. They allow defining the following queries:

  • Exact phrase query

  • Exact fragment query (that is, Take off, give up)

  • Partial exact phrase with a slop parameter (other tokens between the searched terms, that is, "the man" with slop 2 can also match "the strong man", "the old wise man", and so on)

Getting ready

You need a working ElasticSearch cluster.

How to do it...

For executing span queries, we need to perform the following steps:

  1. The main element in span queries is the span_term parameter whose usage is similar to the term of standard query.

    One or more span_term parameters can be aggregated to formulate a span query.

    The span_first query defines a query in which the span_term parameter in the first token or near...