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 matchthe 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:
The main element in span queries is the
span_term
...