Using a match query
ElasticSearch provides a helper to build complex span queries that depend on simple preconfigured settings. This helper is called a match query.
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 a match query, perform the following steps:
The standard usage of a match query simply requires the field name and the query text:
curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{ "query": { "match" : { "parsedtext" : { "field": "nice guy", "operator": "and" } } } }'
If you need to execute the same query as a phrase query, the type of match changes in the
match_phrase
function:curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d '{ "query": { "match_phrase" : { "parsedtext" : "nice guy" } } }'
An extension of the...