身安不如心安,屋宽不如心宽 。

es中text字段中内容为json格式,如何解析json内容做聚合操作

Elasticsearch | 作者 xcan | 发布于2020年10月27日 | 阅读数:4060

es中text字段中内容为json格式,如何解析json内容做聚合操作
场景:
  字段 
     "line" : {
          "type" : "text",
          "analyzer" : "standard"
        },

  line:内容是json格式。
 例如:
{
"RECORDS":[
{
"id":1,
"name":"水电费1",
"type":1,
"status":1,
"outIntype":"1123",
"dataNum":12,
"createTime":"2020/10/26 13:48:21",
"note":"safd手动蝶阀1"
},
{
"id":2,
"name":"史蒂夫2",
"type":2,
"status":2,
"outIntype":"2史蒂夫",
"dataNum":21,
"createTime":"2020/10/26 13:48:56",
"note":"史蒂夫合同号2"
},
{
"id":3,
"name":"不方便3",
"type":3,
"status":1,
"outIntype":"3符",
"dataNum":222,
"createTime":"2020/10/26 13:49:15",
"note":"功能干活呢3"
}
]
}

请问:
  怎么对json内容中的数据解析,聚合,sum,avg等
  比如 输出:dataNum,sum(dataNum)  等
 
有没有解决思路?
 
请教
 
 
已邀请:

guoyanbiao520

赞同来自:

结构这么定义怎么玩都不行

liuxg - Elastic

赞同来自:

你这个是数组,你需要使用 nested 数据类型。请参阅我的文章 Elasticsearch: nested 对象 https://elasticstack.blog.csdn ... 68659

要回复问题请先登录注册