es官网下载
kibana官网下载
IK分词器下载
目标版本: 7.8.0,为防止蜜汁问题,版本建议一致
bin目录下启动文件,启动后打印两个端口,9300为es集群之间的通信端口,9200为浏览器访问端口
基础操作
# 创建索引(创建名为user的索引 PUT http://localhost:9200/user)
PUT /user
# 查看索引信息(查看user的索引信息)
GET /user
# 查看所有索引信息
GET /_cat/indices?v
# 删除指定索引
DELETE /user
# 向user索引中添加(文档)数据
POST /user/_doc/1
{
"name" :"张三",
"age" : 20,
"nickname":"法外狂徒",
"gender" : "男",
"tags" : ["靓仔", "广东仔"]
}
# 查询user索引中id为1的文档数据
GET /user/_doc/1
# 查询所有文档数据
GET /user/_search
# 修改文档数据(局部更新)
POST /user/_update/1
{
"doc" : {
"name" : "张三pulsmini"
}
}
# 删除id为2的文档数据
DELETE /user/_doc/2
# 精确匹配,结果字段过滤,排序,分页
# name=张,返回字段"name","desc","tags","age", age 升序
GET /user/_search
{
"query": {
"match": {
"name": "张"
}
},
"_source": ["name","desc", "tags", "age"],
"sort": [
{
"age": {
"order": "ASC"
}
}
],
"from": 0,
"size": 10
}
# 多条件匹配 (must即and) name=张 and age = 80
GET /test3/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "张"
}
},
{
"match": {
"age": 80
}
}
]
}
}
}
# 多条件匹配 (should即or) name=张 or age = 25
GET /test3/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"name": "张"
}
},
{
"match": {
"age": 25
}
}
]
}
}
}
# 多条件匹配 name=张 and age >= 77 age<= 100
GET /test3/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "张"
}
}
],
"filter": [
{
"range": {
"age": {
"gte": 77,
"lte": 100
}
}
}
]
}
}
}
# 多个条件tags 空格隔开
GET /test3/_search
{
"query": {
"match": {
"tags": "男 精神"
}
}
# 高亮
GET /test3/_search
{
"query": {
"match": {
"name": "张"
}
},
"highlight": {
"pre_tags": "<p class='tagStyle'>",
"post_tags": "</p>",
"fields": {
"name": {}
}
}
}
#geo查询
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "思想"
}
}
],
"filter": [
{
"geo_distance": {
"distance": "1000km",
"location": {
"lat": 54.429442,
"lon": 126.295202
}
}
}
]
}
}
,
"sort": [
{
"_geo_distance": {
"location": [
{
"lat": 54.429442,
"lon": 126.295202
}
],
"unit": "km",
"distance_type": "arc",
"order": "desc",
"validation_method": "STRICT",
"ignore_unmapped": false
}
}
]
}
ik分词器安装,下载完成后,在es plugins目录下新建ik目录, 将ik.zip解压到该目录,重启es即可生效
IKAnalyzer.cfg.xml中可配置自己的字典
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字典 -->
<entry key="myself.dic"></entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords"></entry>
<!--用户可以在这里配置远程扩展字典 -->
<!-- <entry key="remote_ext_dict">words_location</entry> -->
<!--用户可以在这里配置远程扩展停止词字典-->
<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
# 最简拆分
GET _analyze
{
"analyzer": "ik_smart",
"text" : "华为笔记本电脑MateBook D 14 SE版 14英寸 11代酷睿 i5 锐炬显卡 8G+512G 轻薄本/高清护眼防眩光屏 银"
}
# 最大粒度拆分
GET _analyze
{
"analyzer": "ik_max_word",
"text" : "华为笔记本电脑MateBook D 14 SE版 14英寸 11代酷睿 i5 锐炬显卡 8G+512G 轻薄本/高清护眼防眩光屏 银"
}