Having same order in aggregation

Hi,

I have a function score query sorted by score in desc.

In aggregation, however, the order is not the same even though it is also sorted by max score in desc.

How will it be possible to do this?

Cheers,

Not sure what you mean. An aggregation is typically a summary of all docs - both low and high scoring.
Can you share the JSON of your problem request?

Hi Mark,

Thanks for your reply. Imagine that you have parents sorted by _score in desc.

I need parents and their children's ids so I do not need whole children.

In aggregation, I can actually get them but size must be 1000! Because even though it is also sorted by _score, parents are ordered different in aggregation.

What could it be the best practice?

  "aggs": {
    "parents": {
      "terms": {
        "field": "id",
        "size": 1000,
        "order": {
          "max_score": "desc"
        }
      },
      "aggs": {
        "items": {
          "children": {
            "type": "items"
          },
          "aggs": {
            "result": {
              "filter": {
                "term": {
                  "active": true
                }
              },
              "aggs": {
                "platform": {
                  "top_hits": {
                    "_source": "id",
                    "size": 100
                  }
                }
              }
            }
          }
        },
        "max_score": {
          "max": {
            "script": "_score"
          }
        },
        "bucket_truncate": {
          "bucket_sort": {
            "from": 0,
            "size": 1000,
            "sort": {
              "max_score": {
                "order": "desc"
              }
            }
          }
        }
      }
    }
  }

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