es基本操作 + php + golang
php操作es
https://www.cnblogs.com/caiawo/p/15931090.html
https://blog.csdn.net/lxw1844912514/article/details/106687472
go操作es
https://www.codingsky.com/doc/2021/1/2/189.html
增
post http://192.168.133.131:9200/shopping/_doc
//{"title":"小米手机","category":"小米","images":"http://www.gulixueyuan.com/xm.jpg","price":4999}
put http://192.168.133.131:9200/test
put && get http://192.168.133.131:9200/user/_mapping
text-可以分词查询,keyword-不可以分词查询,index=true-可以用于查询字段
//{"properties":{"name":{"type":"text","index":true},"sex":{"type":"keyword","index":true},"tel":{"type":"keyword","index":false}}}
put http://120.24.89.191:9200/user
{"mappings": {"dynamic": false,"properties": {"uid": {"type": "integer"},"name": {"type": "text","analyzer": "ik_max_word"}}}}
删
delete http://192.168.133.131:9200/test
改
post http://192.168.133.131:9200/shopping/_update/1001
//{"doc":{"title":"华为手机"}}
查
查所有index
get http://192.168.133.131:9200/_cat/indices?v
查单条数据
get http://192.168.133.131:9200/shopping/_doc/1001
查index下的所有数据
get http://192.168.133.131:9200/shopping/_search
指定查询字段+分页+排序
{"query":{"match":{"title":"小米"}},"from":0,"size":2,"_source":["title"],"sort":{"price":{"order":"desc"}}}
并且条件
{"query":{"bool":{"must":[{"match":{"title":"小米"}},{"match":{"price":4999}}]}}}
或者条件+范围查询
{"query":{"bool":{"should":[{"match":{"title":"小米"}},{"match":{"title":"华为"}}],"filter":{"range":{"price":{"gt":4000}}}}}}
全文匹配+高亮关键字
{"query":{"match_phrase":{"category":"小"}},"highlight":{"fields":{"category":{}}}}
aggs-聚合操作 price_group-名称,随意起名 terms-分组 price-分组字段 size-过滤原始数据
{"aggs":{"price_group":{"terms":{"field":"price"}}},"size":0}
avg-平均值
es修改mapping映射 https://blog.csdn.net/make_summer/article/details/129880492
es的mapping理解,分词器等等 https://www.cnblogs.com/yswsxf/p/17314715.html
es分词器下载 https://www.jianshu.com/p/0049d4affe86
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了