ElasticSearch概述

ElasticSearch概述

支持RESTful風格數據庫

  • 索引(index)至關於關係型數據庫的一張表
  • 映射(mapping)至關於關係型數據庫中的表結構
  • 文檔(document)至關於關係型數據庫中的字段

kibana調試工具進行調試

PUT person #建立索引
GET person #獲取索引信息
PUT person/_mapping #建立映射
{
  "properties":{
    "name":{
      "type":"keyword"
    },
    "age":{
      "type":"integer"
    }
  }
}
GET person/_mapping 獲取映射信息
PUT student #建立索引的時候添加映射
{
  "mappings": {
    "properties": {
      "name":{
        "type": "text"
      },
      "age":{
        "type": "integer"
      }
    }
  }
}
PUT person/_mapping #添加映射
{
  "properties": {
    "address":{
      "type": "text"
    }
  }
}
PUT person/_doc/1 #指定id添加文檔  不指定id只能夠用post請求方式
{
  "name":"zhangsan",
  "age":20,
  "address":"beijing"
}
GET person/_search #查詢全部
GET person/_search #刪除文檔

analysis-ik中文分詞器

  • 中文分詞器拷貝到ElasticSearch的plugins目錄app

  • 重啓elastic searchelasticsearch

  • 映射(mapping)時候字段的type爲"keyword"表示不分詞工具

  • 映射(mapping)時候字段的type爲"text"表示分詞post

    PUT student #建立索引的時候添加映射
    {
      "mappings": {
        "properties": {
          "name":{
            "type": "text"
          },
          "address":{
            "type": "text",  #text類型爲分詞 須要指定分詞器
            "analyzer":"ik_max_word"
          }
        }
      }
    }
  • ik_smart 粗粒度分詞方式調試

  • ik_max_word 細粒度分詞方式code

    GET _analyze #分詞爲:我 愛 北京 天安門
    {
      "analyzer": "ik_smart"
      , "text": "我愛北京天安門"
    }
    
    GET _analyze#分詞爲:我 愛 北京 天安門 天安 門
    {
      "analyzer": "ik_max_word",
      "text": "我愛北京天安門"
    }

查詢文檔

  • 詞條查詢:term
    • 詞條查詢不會分析查詢條件,只有當詞條和查詢字符徹底匹配時才匹配搜索
  • 全文查詢:match
    • 全文查詢會分析查詢條件,先將查詢條件進行分詞,而後查詢,求並集
相關文章
相關標籤/搜索