- query String search
- query SDL
- query filter
- full-text search
- phrase search
- highlight search
Query String search
Document: GET /index/type/_search
Search for the following parameters:
Took: Milliseconds
Time_out: specifies whether a timeout occurs
_SHards: Data is divided into five fragments. Therefore, all requests are sent to all primary shards or Replica shards
Hits. Total: indicates the number of query results
Hit. max_score: Score is the matching score of a document’s relevance to a search. The more relevant the match, the higher the score
Hit. hits: contains the detailed data of the matched document
The search parameter is attached to the QUERY String of the HTTP request
You can also query and sort by field: GET /index/type/_search? Q =name: zhangsan&sort=age: desc
Query string search is used to retrieve information from the command line using a temporary tool such as curl. However, if the query request is complex, it is difficult to construct this statement in the production environment, so it is rarely used in the query string search
Second, the query DSL
DSL: Domain specified language
HTTP Request Body: The request body can be used to construct query syntax in JSON format. It can construct various complex query statements, which is much more powerful than Query String Search
1, Query all
GET /index/type/_search {
“Query” : {” match_all “: {}}
}
2, according to a field query, and according to a field sort
GET /index/type/_search {
“Query” : {
Match: {
“Name” : “Zhang SAN”
}
},
“Sort” :
{” age “:” desc “}
]
}
3, paging query, from: where to start, size: check several
GET /index/type/_search {
Query: {match_all: {}},
“From” : 1,
“Size” : 1
}
4. Query the specified field
GET /index/type/_search {
Query: {match_all: {}},
“_source” : [” name “, “age”]
}
Third, query filter
The search contains a field and is filtered by a field
GET /index/type/_search {
“Query” : {
“Bool” : {
“Must” : {
“Match” : {
“Name” : “Zhang SAN”
}
},
“Filter” : {
“Range” : {
“Age” : {” gt “: 25}
}
}
}
}
}
四, Full-text search (Full-text search)
GET /index/type/_search {
“Query” : {
“Match” : {
Description: “I am a doctor”
}
}
It will split “I am a doctor”, “I”, “am”, “a”, “doctor”
Phrase search (phrase search)
In contrast to full-text indexing, full-text indexing splits the input search string and inverts it to match one by one. As long as the phrase search can match any broken word, it can return the result. However, the phrase search requires the input search string. It must match exactly the text of the field in the document to be searched, and is returned as a result.
GET /index/type/_search {
“Query” : {
“Match_phrase” : {
Description: “I am a doctor”
}
}
}
6. HighLight search results
GET /index/type/_search {
“Match” : {
“Name” : “zhangsan”
}
“Highlight” : {
“The fileds” : {
“Name” : {}
}
}
}