利用kibana插件對Elasticsearch查詢

利用kibana插件對Elasticsearch查詢python

Elasticsearch是功能很是強大的搜索引擎,使用它的目的就是爲了快速的查詢到須要的數據。django

查詢分類:

  基本查詢:使用Elasticsearch內置查詢條件進行查詢後端

  組合查詢:把多個查詢組合在一塊兒進行復合查詢app

  過濾:查詢同時,經過filter條件在不影響打分的狀況下篩選數據搜索引擎

建立索引
PUT lagou
    {
      "mappings": {
        "job":{
          "properties": {
            "title":{
              "store": true,
              "type": "text",
              "analyzer": "ik_max_word"
            },
            "company_name":{
              "store": true,
              "type": "keyword"
            },
            "desc":{
              "type": "text"
            },
            "comments":{
              "type": "integer"
            },
            "add_time":{
              "type": "date",
              "format": "yyyy-MM-dd"
            }
          }
        }
      }
    }
    

 


PUT lagou    

POST lagou/job
{
  "title":"python django 開發工程師",
  "company_name":"美團",
  "desc":"美團是一個在嗎在嗎在嗎",
  "comments":20,
  "add_time":"2017-4-16"
}

POST lagou/job
{
  "title":"python 爬蟲 開發工程師",
  "company_name":"數據冰山",
  "desc":"專門找數據的一家公司 python",
  "comments":15,
  "add_time":"2016-4-16"
}
POST lagou/job
{
  "title":"django 後端 開發工程師",
  "company_name":"百度科技有限公司",
  "desc":"我也不知道這裏應該寫一點什麼東西了 python",
  "comments":20,
  "add_time":"2017-4-16"
}
POST lagou/job
{
  "title":"python GUI  開發工程師",
  "company_name":"熊貓",
  "desc":"在線視頻教育python",
  "comments":6,
  "add_time":"2017-4-16"
}spa

 

#match查詢,

 

對咱們的輸入進行一個分詞,指明一個字段,會去找這個字段有沒有咱們寫的這個關鍵詞,關鍵詞不區分大小寫,在作分詞的時候會自動對大小寫進行轉換插件

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

#term查詢#

傳遞過來的關鍵詞不會進行任何處理不會解析,text 會分詞,keyword不會分詞的code

GET lagou/job/_search
{
  "query": {
    "term": {
      "company_name": "百度科技有限公司"
    }
  }
}

 #terms查詢orm

只要關鍵字中有一個都會匹配出來視頻

GET lagou/job/_search
{
  "query": {
    "terms": {
      "title": ["django","開發","python"]
    }
  }
}

#控制查詢的返回數量

GET lagou/_search
{
  "query": {
    "match": {
      "title": "python"
    }
  },
  "from": 1,
  "size": 3
}

#從哪開始,數量多少

#match——all  查詢

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

#match_phrase查詢#短語查詢

#slop 兩詞之間最小的距離,query 必須都知足全部的分詞的關鍵詞

GET lagou/_search
{
  "query": {
    "match_phrase": {
      "title": {
        "query": "python django",
        "slop":6
      }
    }
  }
}

 

#multi_match查詢#

好比能夠指定多個字段#好比查詢title和desc這兩個字段裏面包含python 的關鍵詞的文檔GET lagou/job/_search     
#     ^3   指的是權重,什麼比什麼的權重高多少

GET lagou/_search
{
  "query": {
    "multi_match": {
      "query": "python",
      "fields": ["title","desc^3"]
    }
  }
}

#指定返回的字段

GET lagou/_search
{
  "stored_fields": ["title"],
  "query": {
    "match": {
      "title": "開發"
    }
  }
}

#經過sort把結果排序

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

#範圍查詢#range查詢

GET lagou/_search
{
  "query": {
    "range": {
      "comments": {
        "gte": 10,
        "lte": 20,
        "boost": 2.0
      }
    }
  }
}

#range查詢

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

#wildcard 查詢#簡單的模糊查詢

GET lagou/_search
{
  "query": {
      "wildcard": {
        "title": {
          "value": "pyth*n",
          "boost": 2
        }
      }
  }
}
相關文章
相關標籤/搜索