栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将SQL查询转换为ElasticSearch查询

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将SQL查询转换为ElasticSearch查询

假设您使用Elasticsearch 2.x,则有可能在Elasticsearch中 具有 -semantics。我不知道2.0之前的可能性。

您可以使用新的Pipeline Aggregation Bucket Selector
Aggregation
,它仅选择满足特定条件的存储桶:

POST test/test/_search{  "size": 0,  "query" : {      "constant_score" : {          "filter" : { "bool" : {   "must" : [      {"term" : {"fc" : "33"}},      {"term" : {"year" : 2016}},      {"terms" : {"type" : ["a","b","c"] }}   ]}         }      }   },   "aggs": {    "group_by_csgg": {      "terms": {        "field": "csgg",        "size": 100      },      "aggs": {        "sum_amount": {          "sum": { "field": "amount"          }        },        "no_amount_filter": {          "bucket_selector": { "buckets_path": {"sumAmount": "sum_amount"}, "script": "sumAmount == 0"          }        }      }    }  }}

但是,有两个警告。根据您的配置,可能需要启用如下脚本:

script.aggs: truescript.groovy: true

此外,由于它适用于父存储桶,因此不能保证您获得所有金额= 0的存储桶。如果字词聚合仅选择总金额!= 0的字词,则不会有结果。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/387426.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号