simuhunluo

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

  •  
  •   simuhunluo · Nov 26, 2018 · 6316 views
    This topic created in 2736 days ago, the information mentioned may be changed or developed.

    比如说,下面'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 格式显示有问题?下面贴个图片。

    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5853 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 01:54 · PVG 09:54 · LAX 18:54 · JFK 21:54
    ♥ Do have faith in what you're doing.