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"]



