Elasticsearch Query DSL (query language)

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": {} }
}
'

queryThis field represents the definition of a query, where match_allfield represents the query type - all matching documents.

In addition to querythe parameters, other parameters may also be passed. In the following example, we pass a sizeparameter, 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
}
'

fromParameter specifies which document the serial number from the beginning (0-based) sizeparameter 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_alloperations, 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" } }
}
'

Guess you like

Origin www.cnblogs.com/jinbuqi/p/11504375.html