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 ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.