chapter
Elasticsearch provides a json-style query language, called Query DSL (Query domain-specific language). Query Language function is very comprehensive, let's start with a few basic examples.
Back to the example of the previous chapter, we execute this query:
API
GET /bank/_search
{
"query": { "match_all": {} }
}
CURL
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} }
}
'
query
This field represents the definition of a query, where match_all
field represents the query type - all matching documents.
In addition to query
the parameters, other parameters may also be passed. In the following example, we pass a size
parameter, set the number of returned entries:
API
GET /bank/_search
{
"query": { "match_all": {} },
"size": 1
}
CURL
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"size": 1
}
'
Note that, if not specified size
, the default is 10.
The following examples of execution match_all
, return the document 10-19:
API
GET /bank/_search
{
"query": { "match_all": {} },
"from": 10,
"size": 10
}
CURL
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"from": 10,
"size": 10
}
'
from
Parameter specifies which document the serial number from the beginning (0-based) size
parameter specifies the number of documents returned, these two parameters useful for the search results page. Note that, if not specified from
, the default value is 0.
The following example perform match_all
operations, sort the results by account balances in descending order, before returning to 10 (default) document.
API
GET /bank/_search
{
"query": { "match_all": {} },
"sort": { "balance": { "order": "desc" } }
}
CURL
curl -X GET "localhost:9200/bank/_search" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"sort": { "balance": { "order": "desc" } }
}
'