elasticsearch基操

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 轻薄本/高清护眼防眩光屏 银"
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值