Springboot+Elasticsearch+IK分词器实现全文检索(1)

226 阅读1分钟

Springboot+Elasticsearch+IK分词器实现全文检索(1) 下载Elasticsearch 大神的国内下载地址,国外网站的下载地址速度很慢建议使用国内的 blog.csdn.net/weixin_3728… 下载完成后进入bin目录启动 启动成功后 在浏览器或者postman上输入http://localhost:9200/ 成功会输出以下数据

{
  "name" : "wkkmUZK",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "bRf9t_hvRB6w-wJ7e2xiPA",
  "version" : {
    "number" : "6.3.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "053779d",
    "build_date" : "2018-07-20T05:20:23.451332Z",
    "build_snapshot" : false,
    "lucene_version" : "7.3.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

下载kibana可对Elasticsearch进行操作 国内下载地址 blog.csdn.net/weixin_3728… 官网下载地址www.elastic.co/cn/download… 推荐使用国内对速度快 下载后进入bin目录启动服务 启动kibana时要保证已经将Elasticsearch服务启动,因为kibana是依赖于Elasticsearch 启动后输入http://localhost:5601/即可进入页面进行操作

点击页面上以下按钮即可进入编辑页面用来编辑Elasticsearch增删改查语句 在这里插入图片描述

删除某个index

DELETE /blog

新增数据

PUT /abc//创建index
//向index中添加数据
POST /abc/10
{
"first_name" : "John",
"last_name":"Smith",
"age":25,
"about":"I love go to rock climbing",
"interests":["sports","music"]
}

查询数据

GET /person/_doc/1根据id

GET /person/_doc/_search?q=age:25根据age

POST /person/_search
{
"query":{
  "bool": {
    "should": [
      {
        "match": {
          "last_name": "Smith"
        }
      }
    ]
  }
}
}根据姓名等用post就需要这么写

第二种多个条件用should时代表的是or的意思
POST /person/_search
{
"query":{
  "bool": {
    "should": [
      {
        "match": {
          "last_name": "Smith"
        
        
      }
      }
      ,
      {
        "match": {
          "about": "rock"
        }
      }
    ]
  }
}
}


第三种多个条件下用must代表and
POST /person/_search
{
"query":{
  "bool": {
    "must": [
      {
        "match": {
          "last_name": "Smith"
        
        
      }
      }
      ,
      {
        "match": {
          "about": "rock"
        }
      }
    ]
  }
}
}