Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Using span queries


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

The SpanQuery family is a group of queries that control a sequence of text tokens via their positions. Standard queries and filters don't take into account the positional presence of text tokens.

Span queries allow you to define several kinds of queries:

  • The exact phrase query

  • The exact fragment query (such as, Take off, give up)

  • A partial exact phrase with a slop, that is, other tokens between the searched terms (such as 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 and an index populated with the script chapter_05/populate_query.sh, available in the code bundle for this book.

How to do it...

In order to execute span queries, perform the following steps:

  1. The main element in span queries is the span_term...