[ES from entry to actual combat] Nine, full-text search-ElasticSearch-advanced-two query methods

Continue to section 8

Fourth, advanced search

1、SearchAPl

ES supports two basic retrieval methods:

  • By using a REST request URItransmission parameter search ( uri+检索参数)
  • Another is through the use of REST requestbodytransmitting them ( uri+请求体)

1), retrieve information

All retrieval starts from _search
uri+检索参数:

Request or return Explanation
GET bank/_search Retrieve all information under bank, including type and docs
GET bank/_search?q=*&sort=account_number:asc Request parameter retrieval
Explanation of response results:
took Elasticsearch search time (seconds)
time_out Tell us if the search timed out
_shards Tell us how many shards were searched, and count the successful/failed search shards
hits search results
hits.total search results
hits.hits The actual search result array (default is the top 10 documents)
sort Sort result key (key) (If not, sort by score)
score and max_score Relevance score and highest score (for full-text search)

search result:
Insert picture description here

uri+请求体 进行检索:

uri+请求体 进行检索
GET /bank/_search
{
“query”: {
“match_all”: {}
},
“sort”: [
{
“account_number”: “asc”
},
{
“balance”: “desc”
}
]
}
HTTP client tool (POSTMAN), the get request cannot carry the request body. The same is true when we become post. We POST a JSON-style query request body to _search APl.
It should be understood that once the search results are returned, Elasticsearch has completed the request and will not maintain any server-side resources or result cursors (cursors)

search result:
Insert picture description here

Reference document getting-started-search

2、Query DSL

The form used in the previous section is

GET /bank/_search
{
     
     
  "query": {
     
     
    "match_all": {
     
     }
  },
  "sort": [
    {
     
     
      "account_number": "asc"
    },
    {
     
     
      "balance": "desc"
    }
  ]
}

The query language style, we call it Query DSL.

1), basic syntax format

Elastisearch provides a Json style DSl (domain-specific language) that can perform queries. This is called Query DSL.
The query language is very comprehensive and feels a bit complicated at the beginning. The way to really learn it is to start with some basic examples.

  • Typical structure of a query statement

reference:

Elasticsearch Reference

elastic

Getting started with the full-text search engine Elasticsearch

Guess you like

Origin blog.csdn.net/runewbie/article/details/106316691