ElasticSearch
安装
Download Elasticsearch | Elastic
解压即用
elasticSearch head
npm install
npm run start
http.cors.enable: true
http.cors.allow-origin: '*'
#设置跨域
安装kibana
Download Kibana Free | Get Started Now | Elastic
安装IK分词器
存在 ik_max_word为最细粒度划分和ik_smart为最少切分
GET _analyze
{
"analyzer":"ik_smart",
"text":"spring"
}
自己需要的词需要加到自己的ik分词器字典中
<entry key="ext_dict">my.dic</entry>
Rest 风格
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uuaYjahj-1645362543249)(C:\Users\lutrra\AppData\Roaming\Typora\typora-user-images\image-20220220194307265.png)]
-
创建索引
PUT /test1/type/1 { "name":"1", "age":3 } #PUT /索引名/类型名/文档id
-
类型
字符类型 text,keyeord 数值类型 long,integer,short,byte,double,float,half,scaled,float 日期 date 布尔类型 boolean 二进制 binary 等
-
指定字段的类型
PUT /test { "mappings": { "properties":{ "name":{ "type":"text" }, "age":{ "type":"long" } } } }
-
获得信息
GET test
-
查看默认信息
PUT /test3/_doc/1 { "name":"hello", "age":1, "birth":2000-11-11 } GET test3
-
扩展
GET _cat/health //更新 PUT /test3/_doc/1 { "name":"helloooo", "age":1, "birth":2000-11-11 } //版本号会增加 POST PUT /test3/_doc/1/_update { "doc":{ "name":"zs" } }
花式查询
GET myel/user/_search
{
"query":{
"match":{
"name":""
}
}
}
GET myel/user/_search
{
"query":{
"match":{
"name":""
}
},
"_source":["name"]
}
//字段过滤
GET myel/user/_search
{
"query":{
"match":{
"name":""
}
},
"sort":[
{
"age":{
"order":"asc"
}
}
]
}
//通过字段进行排序
GET myel/user/_search
{
"query":{
"match":{
"name":""
}
},
"sort":[
{
"age":{
"order":"asc"
}
}
],
"from":0, //从第几个开始
"size":10 //一页几个
}
//分页
GET myel/user/_search
{
"query":{
"bool":{
"must":[
{
"match":{
"name":""
}
},
{
"match":{
"age":2
}
}
]
}
}
}
//多条件查询 must所有条件都要满足
GET myel/user/_search
{
"query":{
"bool":{
"should":[
{
"match":{
"name":""
}
},
{
"match":{
"age":2
}
}
]
}
}
}
//只要符合一个
GET myel/user/_search
{
"query":{
"bool":{
"must_not":[
{
"match":{
"name":""
}
}
]
}
}
}
//反向操作
GET myel/user/_search
{
"query":{
"bool":{
"must":[
{
"match":{
"name":""
}
}
],
"filter":{
"range":{
"age":{
"lt":10
}
}
}
}
}
}
//gte lte e代表equal gt大于 lt小于
GET myel/user/_search
{
"query":{
"match":{
"tagd":"男 学习 "
}
}
}
//多条件查询 条件空格隔开
term 查询是直接通过倒排索引指定的词条进程精确查找
match 会使用分词器解析
keyword不会被分词器解析
text 会被解析
GET myel/user/_search
{
"query":{
"bool":{
"should":[
{
"term":{
"name":""
}
},
{
"term":{
"age":2
}
}
]
}
}
}
//精确查询多个值
GET myel/user/_search
{
"query":{
"match":{
"name":""
}
},
"highlight":{
"fields":{
"name":{}
}
}
}
//高亮
GET myel/user/_search
{
"query":{
"match":{
"name":""
}
},
"highlight":{
"pre_tags":"<p class='key' style='color:red'>",
"post_tags":"</p>",
"fields":{
"name":{}
}
}
}
//自定义高亮
官方文档[Run Metricbeat on Kubernetes | Metricbeat Reference 8.0] | Elastic