nomilkinmyhome / elasticmapper

Easy generating ElasticSearch mappings based on ORM's models.
https://elasticmapper.readthedocs.io/en/latest/index.html
MIT License
10 stars 0 forks source link

add custom values #2

Closed nomilkinmyhome closed 1 year ago

nomilkinmyhome commented 2 years ago

new parameter for load() - custom_values. it will be a dict that contains custom values per field. for example:

from django.db import models

from elasticmapper import load, SupportedORMs

class User(models.Model):
    username = models.CharField(max_length=30)
    timestamp = models.DateTimeField()

custom_values = {'timestamp': {'type': 'date', 'format': `'yyyy-MM-dd'}}
user_elastic_mapping = load(
    model=User, 
    orm=SupportedORMs.DjangoORM,
    custom_values=custom_values,
)

expected output:

{
    'id': 'int',
    'username': 'text',
    'timestamp': {
        'type': 'date',
        'format': 'yyyy-MM-dd'
    }
}