kibana鐨勬搷浣滄寚鍗桟URD

#es鐨勬枃妗c佺储寮曠殑CRUD鎿嶄綔
#绱㈠紩鍒濆鍖栨搷浣
#鎸囧畾鍒嗙墖鍜屽壇鏈殑鏁伴噺
#shards涓鏃﹁缃笉鑳戒慨鏀
# match
# 浼氬鏌ヨ鐨勫唴瀹硅繘琛屽垎璇嶏紝鍙鍒嗚瘝涓湁涓涓尮閰嶅嵆鍙

GET lagou/job/_search
{
    "query": {
        "match": {
            "title": "python"
        }
    }
}

# term
# 涓嶄細瀵规煡璇㈣瘝鍋氬鐞
GET lagou/job/_search
{
    "query": {
        "term": {
            "title": "python"
        }
    }
}

# terms
# 鏁扮粍涓湁鍖归厤灏辫繑鍥
GET lagou/job/_search
{
    "query": {
        "terms": {
            "title": ["python","鐖櫕"]
        }
    }
}

# 鎺у埗杩斿洖鏁伴噺锛屽彲鐢ㄤ綔鍒嗛〉
GET lagou/job/_search
{
    "query": {
        "match": {
            "title": "python"
        }
    },
    "from":1, # 寮濮嬬殑index 浠0寮濮
    "size":2 # 鏁伴噺
}

# match_all
GET lagou/job/_search
{
    "query": {
        "match_all": {}
    }
}

# match_phrase 鐭鏌ヨ
GET lagou/_search
{
    "query": {
        "match_phrase": {
            "title": {
                "query": "python绯荤粺", # 鍒嗚瘝锛屼笖蹇呴』婊¤冻鎵鏈夌殑璇
                "slop": 6 # 鍒嗚瘝涔嬮棿鐨勬渶灏忚窛绂籶ython涓庣郴缁熶箣闂寸殑璺濈蹇呴』灏忎簬3
            }
        }
    }
}

# multi_match 
GET lagou/job/_search
{
    "query": {
        "multi_match": {
            "query": "python",
            "fields":["title^3", "desc"] # title desc涓よ呬腑婊¤冻鍏朵竴 ^3琛ㄧず鏉冮噸锛岄夋嫨鍥炴潵鐨勭粨鏋滃叾鍒嗘暟浼氭瘮杈冮珮
        }
    }
}

# 杩斿洖鐗瑰畾瀛楁
GET lagou/job/_search
{
    "stored_fields":["title","company_name"], # 杩斿洖鐨勫瓧娈
    "query": {
        "match": {
            "title": "python"
        }
    }
}

# sort
GET lagou/job/_search
{
    "query": {
        "match_all": {}
    },
    "sort": [{
        "comments":{
            "order":"desc"
        }
    }]
}

# range
GET lagou/job/_search
{
    "query": {
        "range": {
            "comments": {
                "gte": 10,
                "lte": 20,
                "boost": 2.0 # 鏉冮噸
            }
        }
    }
}

GET lagou/job/_search
{
    "query": {
        "range": {
            "add_time": {
                "gte": "2017-04-01",
                "lte": "now",
            }
        }
    }
}

# wildcard 妯$硦鏌ヨ
GET lagou/job/_search
{
    "query": {
        "wildcard": {
            "title": {
                "value": "pyth*n",
                "boost": 2.0,
            }
        }
    }
}
bool: {
    "filter":[], # 杩囨护锛屼笉鍙備笌鎵撳垎
    "must":[], # 閮藉繀椤绘弧瓒
    "should":[], # 婊¤冻鑷冲皯涓涓
    "must_not":[] # 涓涓兘涓嶆弧瓒
}
example

# select * from testjob where salary=20
GET lagou/testjob/_search
{
    "query": {
        "bool": {
            "must":{
                "match_all":{}
            },
            "filter":{
                "term":{
                    "salary":[10, 20]
                }
            }
        }
    }
}

# select * from testjob where title="Python"
GET lagou/testjob/_search
{
    "query": {
        "bool": {
            "must":{
                "match_all":{}
            },
            "filter":{
                "term":{
                    "title": "Python" # Python涓簍ext绫诲瀷锛屽叆搴撶殑鏃跺欏凡缁忚浆涓哄皬鍐欎簡锛屽彲浠ュ皢term鏀逛负match
                }
            }
        }
    }
}

# select * from testjob where (salary=20 or title=Python) AND (price != 30)
GET lagou/testjob/_search
{
    "query": {
        "bool": {
            "should": [
                {"term":{"salary":20}},
                {"term":{"title":"python"}}
            ],
            "must_not": {
                "term":{"price":30}
            }
        }
    }
}

# 宓屽鏌ヨ
# select * from testjob where title="python" or (title="elasticsearch" AND salary=30)
GET lagou/testjob/_search
{
    "query": {
        "bool": {
            "should": [
                {"term":{"title":"python"}},
                {
                    "bool":{
                        "must":[
                            {"term":{"title":"elasticsearch"}},
                            {"term":{"salary":30}},
                        ]
                    }
                }
            ]
        }
    }
}

# 杩囨护绌哄拰闈炵┖
# select tags from testjob where tags is not null
GET lagou/testjob/_search
{
    "query": {
        "bool": {
            "filter": {
                "exists": {
                    "field":"tags"
                }
            }
        }
    }
}

# select tags from testjob where tags is null 鎴栬呰瀛楁涓嶅瓨鍦ㄤ篃鍙互
GET lagou/testjob/_search
{
    "query": {
        "bool": {
            "must_not": {
                "exists": {
                    "field":"tags"
                }
            }
        }
    }
}





# 鏌ョ湅鍒嗘瀽鍣ㄨВ鏋愮殑缁撴灉
GET _analyze
{
    "analyzer": "ik_max_word",
    "text": "Python缃戠粶寮鍙戝伐绋嬪笀"
}

# completion suggestor 鑷姩琛ュ叏锛岃瑙佸畼缃戞枃妗
# https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html


# fuzzy妯$硦鎼滅储
GET jobbole/article/_search
{
  "query": {
    "fuzzy": {
      "title":{
        "value": "linux",
        #fuzziness鎸囩殑鏄紪杈戣窛绂 prefix_length鎸囩殑鏄墠闈笉缂栬緫鐨勮窛绂
        "fuzziness": 2,
        "prefix_length": 0
      }
    }
  }
}

# suggest
GET lagou/testjob/_search
{
    "suggest": {
        "my-suggest": {
            "text":"linux" # linu linxx 绛夐兘鍙互鎼滃埌linux
            "completion": {
                "field": "suggest",  # 鑷繁鐢熸垚鐨剆uggest瀛楁
                "fuzzy":{
                    "fuzziness":2
                }
            }
        }
    }
}

# search鍏抽敭瀛梙ighlight
GET jobbole/_search
{
  "query": {
    "multi_match": {
        "query": "鐜嬪皬娉㈢殑姘村钩",
        "fields": ["tags", "title", "content"]
    }
                },
                "from": 0,
                "size": 10,
                "highlight": {
                    "pre_tags": ["<span class='keyWord'>"],
                    "post_tags": ["</span>"],
                    "fields": {
                        "title": {},
                        "content": {}
                    }
                }
}

All posts

Other pages


Deprecated: 鏂囦欢 娌℃湁 comments.php 鐨勪富棰 鑷増鏈 3.0.0 璧峰凡寮冪敤锛屼笖娌℃湁鍙敤鐨勬浛浠c 璇峰湪鎮ㄧ殑涓婚涓寘鍚竴涓 comments.php 妯℃澘銆 in /www/wwwroot/liguoqi.site/wp-includes/functions.php on line 6078

鍙戣〃鍥炲

鎮ㄧ殑鐢靛瓙閭鍦板潃涓嶄細琚叕寮銆 蹇呭~椤瑰凡鐢 * 鏍囨敞