ES

IK分词器两种分词模式



# ik分词器 两种分词模式 ik_smart 最大粒度分词  ik_max_word 最小粒度分词
GET _analyze
{
  "analyzer": "ik_max_word",
  "text": "张凌翔"
}

GET _analyze
{
  "analyzer": "ik_smart",
  "text": "张凌翔"
}


#自定义词典  ik/config/*.dic
GET _analyze
{
  "analyzer": "ik_max_word",
  "text": "我超级喜欢一个人的生活"
}

#创建索引库
PUT /answer
{
  "mappings": {
    "properties": {
      "id": {
        "type": "long"
      },
      "name" : {
        "type": "text"
      },
      "createTime":{
        "type": "date"
      }
    }
  }
}


#插入数据 索引库不存在自动创建
PUT /school/type1/1
{
  "schoolId" : 1001,
  "schoolName" : "石井中学"
}




#查看索引库信息
GET school

#查看统计情况
GET _cat/indices?v


#修改
POST /school/type1/1/_update
{
  "doc":{
    "schoolName" : "五月小学"
  }
}


PUT /blog/tag/1
{
  "name" :"golang并发编程",
  "content" : "go是一门编程语言....",
  "tags" : ["后端","并发"]
}


PUT /blog/tag/2
{
  "name" :"PHP入门到入土",
  "content" : "PHP是世界上最好的语言!",
  "tags" : ["后端","拍黄片"]
}

PUT /blog/tag/3
{
  "name" :"Python",
  "content" : "人生苦短,我用Python!",
  "tags" : ["机器学习","人工智障"]
}

PUT /blog/tag/4
{
  "name" :"JAVA 教程",
  "content" : "上天入地,无所不能!",
  "tags" : ["并发","服务端"]
}


#简单查询
###获取数据
GET /blog/tag/1


# 根据条件查询、过滤字段、排序、分页
GET /blog/tag/_search
{
  "query": {
    "match": {
      "tags" : "后端"
    }
  },
  "_source": ["content","tags"],
  "sort": [
    {
      "_id": {
        "order": "desc"
      }
    }
  ],
  "from": 0,
  "size": 2
}


#复合查询 多条件查询 must-->and
GET /blog/tag/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "tags": "后端"
          }
        },
        {
          "match": {
            "name": "JAVA"
          }
        }
      ]
    }
  }
}

#复合查询  should-->or
GET /blog/tag/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": "JAVA"
          }
        },
        {
          "match": {
            "tags": "并发"
          }
        }
      ]
    }
  }
}

#过滤
GET /blog/tag/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "tags": "后端"
          }
        }
      ],
      "filter": {
        "term": {
          "name": "VALUE"
        }
      }
    }
  }
}



































Java