Introduction Query Language

source:https://www.elastic.co/guide/en/elasticsearch/reference/6.4/getting-started-query-lang.html

es provide query Json format. We mentioned in the query DSL. This query language is very reliable, although it seems difficult to understand difficult to learn, but we can quickly learn some simple examples.

Returning to our previous query:

curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} }
}
'

Analyze the query, query definitions tell us part of the query, match_all query is part of the composition, which means the return of a particular index all documents.

In addition to query parameters, we can also be influenced by other parameters of our search results, the following example is an incoming size parameters, we have previously passed through the sort parameters:

curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"size": 1
}
'

Note that the default size itself is 10

The following history is to return all the data in the document Article 10-19

curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"from": 10,
"size": 10
}
'

This parameter specifies the coordinates from the first return, size This parameter specifies how many documents are returned. This combination is very useful when we use paged search,

Note from not specified, the default is 0

The following example is a balance in descending order, the top ten return data (default 10):

curl -X GET "localhost:9200/bank/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": { "match_all": {} },
"sort": { "balance": { "order": "desc" } }
}
'

 

Guess you like

Origin www.cnblogs.com/supermanwx/p/11926798.html