栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elasticsearch-学习记录

elasticsearch-学习记录

1:elasticsearch结构

elasticsearch数据库>索引库>类型>下标

2:新建索引库

设置mapping设置索引type类型结构 > 类似设置mysql表数据结。
如下:新建mapping,索引-bloag索引,type表-hello,_mappings -设置mappings,里面定义了3个字段

POST /blog/hello/_mappings
{
  "hello":{
    "properties":{
      "id":{
        "type":"long",
        "store":true 
      },
      "title":{
        "type":"text",
        "store":true,
        "index":true,
        "analyzer":"standard" 
      },
      "content":{
        "type":"text",
        "store":true,
        "index":true,
        "analyzer":"standard" 
      }
    }
  }
}

根据索引添加数据

POST /blog1/hello/0
{
  "id":0,
  "title":"库里加冕NBA历史三分王",
  "content":"库里加冕NBA历史三分王具体内容"
}

搜索
1:terms搜索,搜索包含下面,可以搜索多个,不过只能一个一个字搜索

POST /blog1/hello/_search
{
  "query":{
    
    "terms": {
      "title": [
        "香","8"
        ]
    }
  }
}

2:query_string搜索
注意:搜索的内容是英文的话,会根据空格隔开,然后搜索,中文搜索,启用了es默认分词器,会一个字一个字的拆开搜索,对此我们要下载分词器插件进行搜索,比如ik,把ik下载下来,直接赋值下来放到我们的es的plugins目录下,重启es就行,然后使用分词器的时候,我们新建mappings的时候可以设置分词器, ik分词器有两种类型,ik_smart,ik_max_word两种类型,后面一种搜索颗粒比较细。
1:新建mappings

POST /blog/hello/_mappings
{
  "hello":{
    "properties":{
      "id":{
        "type":"long",
        "store":true 
      },
      "title":{
        "type":"text",
        "store":true,
        "index":true,
        "analyzer":"ik_max_word" 
      },
      "content":{
        "type":"text",
        "store":true,
        "index":true,
        "analyzer":"ik_max_word" 
      }
    }
  }
}

2:搜索

POST /blog1/hello/_search
{
  "query":{
    "query_string": {
      "default_field": "title",
      "query": "锣8套房的三"
    }
  }
}
3:elasticsearch集群

配置文件添加:修改config>elasticsearch.yml文件

#节点1的配置信息:
#集群名称,保证唯一
cluster.name: my-es
#节点名称,必须不一样
node.name: node-2
#必须为本机的ip地址
network.host: 127.0.0.1
#服务端口号,在同一机器下必须不一样
http.port: 9202
#集群间通信端口号,在同一机器下必须不一样
transport.tcp.port: 9302
#设置集群自动发现机器ip集合
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/673884.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号