0

I have a elastic search index with following mapping

 {
  "probe_alert" : {
    "mappings" : {
      "alert" : {
        "properties" : {
          "id" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "probeChannelId" : {
            "type" : "long"
          },
          "severity" : {
            "type" : "integer"
          },
        }
      }
    }
  }
}

Sample indexed data : For each channel index has a severity value

[
      {
        "_index" : "probe_alert",
        "_type" : "alert",
        "_id" : "b_cu0nYB8EMvknGcmMxk",
        "_score" : 0.0,
        "_source" : {
          "id" : "b_cu0nYB8EMvknGcmMxk",
          "probeChannelId" : 15,
          "severity" : 2,
        }
      },
      {
        "_index" : "probe_alert",
        "_type" : "alert",
        "_id" : "b_cu0nYB8EMvknGcmMxk",
        "_score" : 0.0,
        "_source" : {
          "id" : "b_cu0nYB8EMvknGcmMxk",
          "probeChannelId" : 17,
          "severity" : 5,
        }
      },
      {
        "_index" : "probe_alert",
        "_type" : "alert",
        "_id" : "b_cu0nYB8EMvknGcmMxk",
        "_score" : 0.0,
        "_source" : {
          "id" : "b_cu0nYB8EMvknGcmMxk",
          "probeChannelId" : 18,
          "severity" : 10,
        }
      },
      {
        "_index" : "probe_alert",
        "_type" : "alert",
        "_id" : "b_cu0nYB8EMvknGcmMxk",
        "_score" : 0.0,
        "_source" : {
          "id" : "b_cu0nYB8EMvknGcmMxk",
          "probeChannelId" : 19,
          "severity" : 5,
        }
      },
      {
        "_index" : "probe_alert",
        "_type" : "alert",
        "_id" : "b_cu0nYB8EMvknGcmMxk",
        "_score" : 0.0,
        "_source" : {
          "id" : "b_cu0nYB8EMvknGcmMxk",
          "probeChannelId" :20,
          "severity" : 10,
        }
      }
    ]

I have done terms aggregation for fetching max severity value for a single probeChannelId but now I want to aggregate on multiple values of probeChannelId and get max value of severity. Expected Result :

"aggregations" : {
    "aggs_by_channels" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : [15,17],
          "doc_count" : 1,
          "aggs_by_severity" : {
            "value" : 5.0
          }
        },
        {
          "key" : [18,19,20],
          "doc_count" : 1,
          "aggs_by_severity" : {
            "value" : 10.0
          }
        }
      ]
    }
  }

In response i want group of values probeChannelId to have highest severity value

3
  • can you please share some sample index data and expected search result ? Commented Jan 14, 2021 at 8:46
  • @ESCoder i have added the sample data and expected response Commented Jan 14, 2021 at 9:09
  • Also i have checked Adjacency matrix aggregation , but that aggregates data across groups and not individual groups. Commented Jan 14, 2021 at 9:11

1 Answer 1

1

If you want to get the highest severity value, among a set of documents, then you can try out the below query using the Adjacency matrix aggregation

Search Query:

{
  "size": 0,
  "aggs": {
    "interactions": {
      "adjacency_matrix": {
        "filters": {
          "[15,17]": {
            "terms": {
              "probeChannelId": [
                15,
                17
              ]
            }
          },
          "[18,19,20]": {
            "terms": {
              "probeChannelId": [
                18,
                19,
                20
              ]
            }
          }
        }
      },
      "aggs": {
        "max_severity": {
          "max": {
            "field": "severity"
          }
        }
      }
    }
  }
}

Search Result:

"aggregations": {
    "interactions": {
      "buckets": [
        {
          "key": "[15,17]",
          "doc_count": 2,
          "max_severity": {
            "value": 5.0           // note this
          }
        },
        {
          "key": "[18,19,20]",
          "doc_count": 3,
          "max_severity": {
            "value": 10.0        // note this
          }
        }
      ]
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man, understood how Adjacency matrix aggregation will work. @ESCoder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.