How to sort on second same (field) value

Hi people,
I ran into an sorting problem, which is very hard for me to find out how to do it.

What i want to achieve is to query the data to sort it in a way that the second(or higher) of the same configuration_id is at the end of the results.
Is there a way to to this? I assume it could be done with some aggregations, but i don't ahve any idea where to start with this.
Could you guys help me to figure this out?

This is the data:

{
    "_index": "products",
    "_source": {
        "name": "Product 1",
        "configuration_id": "1"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product 2",
        "configuration_id": "1"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product 3",
        "configuration_id": "1"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product 4",
        "configuration_id": "2"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product 5",
        "configuration_id": "2"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product ",
        "configuration_id": "3"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product7",
        "configuration_id": "3"
    }
}

This is an example on how i would like to get the data in the result:

{
    "_index": "products",
    "_source": {
        "name": "Product 1",
        "configuration_id": "1"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product 4",
        "configuration_id": "2"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product ",
        "configuration_id": "3"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product 2",
        "configuration_id": "1"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product 3",
        "configuration_id": "1"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product 5",
        "configuration_id": "2"
    }
},
{
    "_index": "products",
    "_source": {
        "name": "Product7",
        "configuration_id": "3"
    }
}

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