先前條件1信峻、elasticsearch測試數(shù)據(jù)集
https://blog.csdn.net/qq_35843514/article/details/120205873
先前條件2鳖昌、批量插入
POST bank/account/_bulk
1毛秘、Query DSL基本查詢使用
GET bank/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"balance": {
"order": "desc"
}
}
],
"from": 0,
"size": 5,
"_source": ["firstname","lastname","balance"]
}
-- 其中"match_all"表示匹配所有
-- “sort”表示查詢條件 是按"balance"降序排序
-- "from"查詢起始位置
-- "size"查詢數(shù)據(jù)的量(這里是從第0號開始之众,顯示5條數(shù)據(jù)竹祷,相當(dāng)于sql語句的limit)
-- "_source"查詢出需要顯示的字段
2押逼、match既可以作為模糊查詢申尼,全文檢索
GET bank/_search
{
"query":{
"match": {
"address": "Mill Lane"
}
}
}
-- "address"中包含"Mill“、”Lane"鹉戚、“Mill Lane”都會被查詢出來(相當(dāng)于分詞)
-- 全文檢索最后會按評分排序
3鲜戒、短語匹配之"match_phrase"
GET bank/_search
{
"query":{
"match_phrase": {
"address": "Mill Lane"
}
}
}
-- "match_phrase"表示只會匹配"address"中包含"Mill Lane"的記錄
4、多字段匹配之 "multi_match"
GET bank/_search
{
"query":{
"multi_match": {
"query": "mill",
"fields": ["address","city"]
}
}
}
-- 只要字段"address"或"city"中包含"mill"的記錄就會被查詢出來(如果查詢的是多字段也會進行分詞)
5抹凳、復(fù)合查詢之"bool"
GET bank/_search
{
"query":{
"bool": {
"must": [
{"match": {
"gender": "M"
}},
{"match": {
"address": "mill"
}}
],
"must_not": [
{"match": {
"age": "18"
}}
],
"should": [
{"match": {
"lastname": "Wallace"
}}
]
}
}
}
-- "must"必須匹配
-- "must_not"必須不匹配
-- "should"可以匹配遏餐,可以不配配,匹配的話相關(guān)性評分會高
6赢底、結(jié)果過濾之"filter"
GET bank/_search
{
"query":{
"bool": {
"must": [
{"range": {
"age": {
"gte": 18,
"lte": 30
}
}
}
]
}
}
}
GET bank/_search
{
"query":{
"bool": {
"filter": {
"range": {
"age": {
"gte": 18,
"lte": 30
}
}
}
}
}
}
7失都、非text文本字段之"term",全文用"match"
GET bank/_search
{
"query":{
"term": {
"balance":"32838"
}
}
}