##########################Advanced query
Sub-condition query: query the specified value of a specific field 1. Query
context
In the query process, in addition to judging documents In addition to whether the query conditions are met,
ES will also calculate a -_score to identify the degree of matching, which is used to judge how good the target and query conditions are.
1. Full text query: for text type data
1. Fuzzy matching: match
localhost:9200/book /_search
method: POST
{
"query":{
"match":{
"author":"haha"
}
}
}
2. Phrase match (match_phrase)
localhost:9200/book/_search
method: POST
{
"query":{
"match_phrase":{
"author":"haha"
}
}
}
3. Multi-field fuzzy matching (multi_match)
localhost:9200/book/_search
method: POST
{
"query":{
"multi_match":{
"query":"haha",
"fields":["author","title" ]
}
}
}
4. Grammar query (qurry_string)
localhost:9200/book/_search
method: POST
{
"query":{
"qurey_string":{
"query":"Haha or Dafa"
}
}
}
{
"query":{
"qurey_string":{
"query":"哈哈 or 大法",
"fields":["title","author"]
}
}
}
2. Field-level query: for structured data, such as numeric dates, etc.
localhost:9200/book/_search
method: POST
{
"query":{
"term":{ ##Field keyword
"author":"Liu Dazhuang"
}
}
}
{
"query":{
"range":{ ######Range
"word_count":e{
"gte":1000 ###Greater than or equal to
"lte":10000 ###Less than or equal to
}
}
}
}
2. Filter context combined with bool keyword to use
qualified query: query with a certain logical combination of sub-conditions
In the query process, only to determine whether the document meets the conditions, only Yes or No
localhost:9200/book/_search
method: POST
{
" query":{
"bool":{
"filter":{
"term":{
"word_count":1000
}
}
}
}
}
1. Most filter queries do not have query speed 2. The filter does
not calculate the relevance score, and the results There will be cache, high efficiency
3. Full-text search, scoring and sorting use query (other generally use filter)
4. Yes and no filtering, exact match, use filter
3. Compound condition query
localhost:9200/_search
method: POST
1. Fixed score query (constant_score) does not support match, only filter
{
"query":{
"constant_score":{ ######fixed score query keyword
"filter":{
"match":{
"title":"Dafa"
}
},
"boost":2 ###Specify the score
}
}
}
2. Boolean query (the difference between should and must and must_not)
#### ################should
{
"query":{
"bool":{
"should":[ ###The condition inside is "or" relation
{
"match":{
"author":"Haha"
},
"match":{
"title":"Dafa"
}
}
]
}
}
}
##################must
{
"query" :{
"bool":{
"must":[ ###The condition inside is "and" relationship
{
"match":{
"author":"haha"
},
"match":{
"title":"大法"
}
}
]
}
}
}
################must+filter
{
"query":{
"bool":{
"must":[ ###The condition inside is "and" Relation
{
"match":{
"author":"Haha"
},
"match":{
"title":"Dafa"
}
}
],
"filter":{
"term":{
"word_count":1000
}
}
}
}
}
####################must_not
{
"query":{
"bool":{
"must_not":{
"term":{
"author":"张三"
}
}
}
}
}