Using a QueryString query
In the previous recipes, we saw several types of query that use text to match the results. The QueryString query is a special type of query that allows you to define complex queries by mixing field rules.
It uses the Lucene query parser in order to parse text to complex queries.
Getting ready
You need a working ElasticSearch cluster and an index populated with the GeoScript chapter_05/populate_query.sh
, available in the code bundle for this book.
How to do it...
We want to retrieve all the documents that match parsedtext
, joe
, or bill
, with a price
between 4
and 6
.
To execute this QueryString query, this is how the code will look:
curl -XPOST 'http://127.0.0.1:9200/test-index/test-type/_search?pretty=true' -d ' { "query": { "query_string": { "default_field": "parsedtext", "query": "(bill OR joe) AND price:[4 TO 6]" } } }'
The search will return three results.
How it works...
The QueryString query is one of the most powerful types of queries. The...