Separate result by category

Hello , I have nested filed .
And I want to bring the result separated by broker , something like this -

[ "broker_one" => [
   result
],
"broker_two" => [
     result
]

I know that I can aggregate the result , and count them by aggregation .
but what I wold like to do is to separate the result , I dont know if with aggregation . wold be possible .

My Search -



GET /metric-property-broker-daily-2023-05/_search
{
  "size": 100,
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "real_estate",
            "query": {
              "match": {
                "real_estate.id": 1
              }
            }
          }
        },
        {
          "nested": {
            "path": "broker",
            "query": {
              "bool": {
                "should": [
                  {
                    "match": {
                      "broker.id": 103
                    }
                  },
                  {
                    "match": {
                      "broker.id": 109
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "range": {
            "timestamp": {
              "gte": "2023-05-04",
              "lte": "2023-06-05"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "brokers": {
      "nested": {
        "path": "broker"
      },
      "aggs": {
        "broker_one": {
          "filter": {
            "bool": {
              "filter": [
                {
                  "term": {
                    "broker.id": 103
                  }
                }
              ]
            }
          }
        },
        "broker_two": {
          "filter": {
            "bool": {
              "filter": [
                {
                  "term": {
                    "broker.id": 109
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}


The result -

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 3,
    "hits": [
      {
        "_index": "metric-property-broker-daily-2023-05",
        "_id": "Mlbyz4kBgvOTcbqQPyPj",
        "_score": 3,
        "_source": {
          "timestamp": "2023-05-31",
          "count_property": 0,
          "sun_price": 0,
          "real_estate": {
            "id": 1,
            "name": "Real Estate One"
          },
          "broker": {
            "id": 103,
            "name": "Bob "
          }
        }
      },
      {
        "_index": "metric-property-broker-daily-2023-05",
        "_id": "NFbyz4kBgvOTcbqQPyPj",
        "_score": 3,
        "_source": {
          "timestamp": "2023-05-04",
          "count_property": 0,
          "sun_price": 0,
          "real_estate": {
            "id": 1,
            "name":  "Real Estate One"
          },
          "broker": {
            "id": 103,
            "name": "Bob "
          }
        }
      },
      {
        "_index": "metric-property-broker-daily-2023-05",
        "_id": "NVbyz4kBgvOTcbqQPyPj",
        "_score": 3,
        "_source": {
          "timestamp": "2023-05-05",
          "count_property": 0,
          "sun_price": 0,
          "real_estate": {
            "id": 1,
            "name": "Real Estate One"
          },
          "broker": {
            "id": 109,
            "name": "James "
          }
        }
      },
          ]
  },
  "aggregations": {
    "brokers": {
      "doc_count": 3,
      "broker_one": {
        "doc_count": 2
      },
      "broker_two": {
        "doc_count": 1
      }
    }
  }
}

Does have any how to separate the result like this -
separating -
broker_one: [{ result }], broker_two: [{ result }]

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 3,
    "hits": [{
    "broker_one": [
  {
        "_index": "metric-property-broker-daily-2023-05",
        "_id": "Mlbyz4kBgvOTcbqQPyPj",
        "_score": 3,
        "_source": {
          "timestamp": "2023-05-31",
          "count_property": 0,
          "sun_price": 0,
          "real_estate": {
            "id": 1,
            "name": "Real Estate One"
          },
          "broker": {
            "id": 103,
            "name": "Bob "
          }
        }
      },
      {
        "_index": "metric-property-broker-daily-2023-05",
        "_id": "NFbyz4kBgvOTcbqQPyPj",
        "_score": 3,
        "_source": {
          "timestamp": "2023-05-04",
          "count_property": 0,
          "sun_price": 0,
          "real_estate": {
            "id": 1,
            "name":  "Real Estate One"
          },
          "broker": {
            "id": 103,
            "name": "Bob "
          }
        }
      }

    ],

     "broker_two": [
      {
        "_index": "metric-property-broker-daily-2023-05",
        "_id": "NVbyz4kBgvOTcbqQPyPj",
        "_score": 3,
        "_source": {
          "timestamp": "2023-05-05",
          "count_property": 0,
          "sun_price": 0,
          "real_estate": {
            "id": 1,
            "name": "Real Estate One"
          },
          "broker": {
            "id": 109,
            "name": "James "
          }
        }
      }
      ]
     }]
  },
  "aggregations": {
    "brokers": {
      "doc_count": 3,
      "broker_one": {
        "doc_count": 2
      },
      "broker_two": {
        "doc_count": 1
      }
    }
  }
}

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