Chain or relate results of one response to another in msearch

Hello and good day! With the pandemic COVID19 lurking around, hope all of you guys are fine

Just a quick question, with the past year, I've been tasked with certain endpoints that require Elasticsearch queries. I'm now in the optimization part, and just so happened I stumble upon the Multi Search or commonly known as msearch

Now with the idea of msearch, I've thought I could lessen the number of searches that I make to our ES servers. Before, I'm making 2 search queries, and now my aim is to have 1 msearch query

Is there a way for the first aggs response of msearch be related to the next aggregations? I mean, is there a way for me to get the response of the first aggs in msearch then past it to the next in run-time?

Example Scenario:

FIRST AGGS
I'm getting the MAX VALUE of a certain field

"aggs" => [
    'MAX_SVALUE' => [
        'max' => [
            'field' => 'latest.soc_mm_score'
        ]
    ],
]

SECOND AGGS
Using the max value above

Please note, the $mxs there, is a PHP based array, it contains the max values form the FIRST AGGS

"aggs" => [
    "SVALUE" => [
        "terms" => [
            "script" => [
                "source"=>"
                    double temp = Double.parseDouble((((doc['latest.soc_mm_score'].value * 10) / ".$mxs[$platforms[$p]].").toString()));
                    return temp;
                ",
                "lang"=>"painless"
            ],
            "size"=> 10000
        ]
    ]
]

Thank you in advance for your help!

Hey,

every search operation within an msearch request is fully independent from each other, so the answer to this one would be no.

What are you trying to achieve with the second aggregation? Maybe we can find a way to do this in a single request or without using scripting to keep performance high.

--Alex

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.