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
    • 全文查询会分析查询条件,先将查询条件进行分词,而后查询,求并集
相关文章
相关标签/搜索