[ES from entry to actual combat] Ten, full-text search-ElasticSearch-Advanced-QueryDSL basic use&match_all

Continue to section 9

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
{
    
    
	QUERY_NAME:{
    
    
		ARGUMENT: VALUE,
		ARGUMENT: VALUE,
		...
	}
}

E.g:

GET /bank/_search
{
  "query": {
    "match_all": {}
  }
}

Insert picture description here

  • If it is for a certain field, its structure is as follows:
{
    
    
	QUERY_NAME:{
    
    
		FIELD_NAME:{
    
    
			ARGUMENT: VALUE,
			ARGUMENT: VALUE,
			...
		}
	}
}

E.g:

GET /bank/_search
{
“query”: {
“match_all”: {}
},
“sort”: [
{
“balance”: {
“order”: “desc”
}
}
],
“from”: 0,
“size”: 5
}

-query defines how to query; -match_all query type [represents all of the query], es can combine a lot of query types in query to complete complex queries
-in addition to query parameters, we can also pass other parameters to change the query result. Such as sort, size;
-from+size limit, complete the paging function;
-sort sort, multi-field sorting, the subsequent fields will be sorted internally when the previous fields are equal, otherwise the previous order prevails

Insert picture description here

2), return some fields

GET /bank/_search
{
    
    
  "query": {
    
    
    "match_all": {
    
    }
  },
  "sort": [
    {
    
    
      "balance": {
    
    
        "order": "desc"
      }
    }
  ],
  "from": 0,
  "size": 5,
  "_source": ["balance","firstname"]
}

Returns only _sourcein the specified field, similar in MySQLselect field_1,field_2,... from table
Insert picture description here

Reference document-query-dsl


reference:

Elasticsearch Reference

elastic

Getting started with the full-text search engine Elasticsearch

Guess you like

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