V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
simuhunluo
V2EX  ›  Elasticsearch

elasticsearch 里面使用 script_fields 计算得到的字段,如何在别处引用该字段?

  •  
  •   simuhunluo · 2018-11-26 17:48:43 +08:00 · 3155 次点击
    这是一个创建于 1949 天前的主题,其中的信息可能已经有所发展或是发生改变。

    比如说,下面'c'是用 script_fields 计算得到的字段( ps:计算方法是 c=a-b )。 我想按 cost_type 聚合,计算 sum(c)。如何实现呢?求大致思路,需要使用 es 的什么方法? 主要是表结构现在已经不适合再单独添加一个 c 字段了。

    {
        "_index":"table3",
        "_type":"type",
        "_id":"hr3PTmcBaJU8s-D3Q8kc",
        "_score":1,
        "_source":{
            "cost_type":"cost",
            "a":44,
            "b":10
        },
        "fields":{
            "c":[
                34
            ]
        }
    }
    

    貌似 json 格式显示有问题?下面贴个图片。

    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3199 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:24 · PVG 22:24 · LAX 07:24 · JFK 10:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.