# Alphanumeric sort on child field

**URL:** <https://discuss.elastic.co/t/alphanumeric-sort-on-child-field/155356>\
**Category:** Elasticsearch\
**Created:** [November 5, 2018, 8:04am UTC](https://discuss.elastic.co/t/alphanumeric-sort-on-child-field/155356 "2018-11-05T08:04:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andyhoang](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@andyhoang](https://discuss.elastic.co/u/andyhoang)\
**Post date:** [November 5, 2018, 8:04am UTC](https://discuss.elastic.co/t/alphanumeric-sort-on-child-field/155356/1 "2018-11-05T08:04:46Z")

</div>

Hi guys,  
I'm using es5. I currently have a child-parent relations ship in same indice: `prod`  
parent

```auto
{
  "prod": {
    "mappings": {
      "Parcel": {
        "properties": {
          "imported_date": {
            "type": "date"
          },
         ....
          "delivered_date": {
            "type": "date"
          },
          "parcel_org_dict": {
            "type": "object",
            "enabled": false
          },
        }
      }
    }
  }
}

```

and the child

```auto
{
  "prod": {
    "mappings": {
      "ParcelOrganization": {
        "_parent": {
          "type": "Parcel"
        },
        "_routing": {
          "required": true
        },
        "properties": {
          "carrier_reference": {
            "type": "keyword"
          },
          "organization_id": {
            "type": "integer"
          },

        }
      }
    }
  }
}

```

My query on Parent:

```auto
{
  "sort": [
    {
      "imported_date": "asc"
    }
  ],
  "query": {
    "bool": {
      "must": [
        {
          "has_child": {
            "query": {
              "terms": {
                "organization_id": [
                  949
                ]
              }
            },
            "inner_hits": {},
            "type": "ParcelOrganization"
            
          }
        },
        {
          "bool": {
            "should": []
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 25
}

```

It is sorted by the field `imported_date` of the parent, very simple.  
Now I want to sort by `carrier_reference` using asc, or desc But dont know where to start.  
I did read about  
`https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-weight`  
and  
`https://gist.github.com/matthiasg/2b8748cfdf919ce77c3fd0438613cee6`  
Was my approach doable? Can I combine sort by child field and parent field?  
Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 3, 2018, 8:04am UTC](https://discuss.elastic.co/t/alphanumeric-sort-on-child-field/155356/2 "2018-12-03T08:04:47Z")

</div>

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