'We use this function in value_list and ordering to get the correct fields name'

def _django_to_es_field(self, field):

    from django.db import models
    prefix = ''
    if field.startswith('-'):
        prefix = '-'
        field = field.lstrip('-')
    if (field in ['id', 'pk']):
        return ('_id', models.AutoField)
    try:
        (dj_field, _, _, _) = self.model._meta.get_field_by_name(field)
        if isinstance(dj_field, models.ForeignKey):
            return (((prefix + field) + '_id'), models.ForeignKey)
        else:
            return ((prefix + field), dj_field)
    except models.FieldDoesNotExist:
        pass
    return ((prefix + field.replace(FIELD_SEPARATOR, '.')), None)
