es的一些实用案例
表结构:
GET ehirestate/_mapping
{ "ehirestate" : { "mappings" : { "ehire" : { "properties" : { "activeTime" : { "type" : "long" }, "ctmId" : { "type" : "integer" }, "date" : { "type" : "integer" }, "downloadCount" : { "type" : "long" }, "inboxExport" : { "type" : "long" }, "inboxSearch" : { "type" : "long" }, "inboxView" : { "type" : "long" }, "loginCount" : { "type" : "long" }, "otherView" : { "type" : "long" }, "resumeSearch" : { "type" : "long" }, "resumeTemDown" : { "type" : "long" }, "resumeView" : { "type" : "long" }, "userId" : { "type" : "integer" } } } } } }
实例一:
功能:1- 对用户userId进行装桶,对resumeView进行聚合后排序;
2- 对date进行范围性匹配;
3- 对会员ctmid进行精确匹配;
4- 返回结果是聚合后的loginCount和resumeView
查询语句:
GET ehirestate/_search?size=0 { "query": { "bool" : { "filter" : [ { "term" : { "ctmId" : { "value" : 1475127 } } }, { "range": { "date": { "gte": 20191201, "lte": 20191231 } } } ] } }, "aggs": { "father": { "terms": { "field": "userId",
"size": 1, "order": { "child": "desc" } }, "aggs": { "child": { "sum": { "field": "resumeView" } }, "loginCount":{ "sum": { "field": "loginCount" } } } } } }
返回结果:
{ "took" : 2, "timed_out" : false, "_shards" : { "total" : 2, "successful" : 2, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 339, "max_score" : 0.0, "hits" : [ ] }, "aggregations" : { "father" : { "doc_count_error_upper_bound" : -1, "sum_other_doc_count" : 338, "buckets" : [ { "key" : 6231765, "doc_count" : 1, "loginCount" : { "value" : 3.0 }, "child" : { "value" : 476.0 } } ] } } }
功能二:
对聚合后的排序后取出对应的文档数据
查询语句:
GET ehirestate/_search { "query": { "bool": { "filter": [ { "term": { "ctmId": { "value": 1475127 } } }, { "range": { "date": { "gte": 20191201, "lte": 20191231 } } } ] } }, "size": 0, "aggs": { "father": { "terms": { "field": "userId", "order": { "top_hit": "desc" }, "size": 1 }, "aggs": { "top_tags_hits": { "top_hits": {} }, "top_hit": { "sum": { "script": { "source": "doc.resumeView" } } } } } } }
返回结果:
{ "took" : 3, "timed_out" : false, "_shards" : { "total" : 2, "successful" : 2, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 339, "max_score" : 0.0, "hits" : [ ] }, "aggregations" : { "father" : { "doc_count_error_upper_bound" : -1, "sum_other_doc_count" : 338, "buckets" : [ { "key" : 6231765, "doc_count" : 1, "top_hit" : { "value" : 476.0 }, "top_tags_hits" : { "hits" : { "total" : 1, "max_score" : 1.4E-45, "hits" : [ { "_index" : "ehirestate", "_type" : "ehire", "_id" : """1475127623176520191203""", "_score" : 0.0, "_routing" : "1475127", "_source" : { "date" : 20191203, "activeTime" : 0, "inboxView" : 0, "resumeTemDown" : 0, "userId" : 6231765, "loginCount" : 3, "inboxExport" : 0, "otherView" : 0, "inboxSearch" : 1, "resumeSearch" : 73, "ctmId" : 1475127, "downloadCount" : 2, "resumeView" : 476 } } ] } } } ] } } }
标签:
ElasticSearch
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2018-12-11 ElasticSearch查询
2018-12-11 ElasticSearch集群的基本原理
2018-12-11 ElasticSearch基础