Skip to content

How to add a mapping on the Document class #475

Open
@pulse-mind

Description

@pulse-mind

I have a Document class like that :

@registry.register_document
class MyDataDocument(Document):    
    data_json = fields.ObjectField()
    
    def prepare_data_json(self, instance):
        return instance.data_json    
        
    class Index:
        name = "mydata"
        settings = {"number_of_shards": 1, "number_of_replicas": 0}



    class Django:
        model = MyData
        fields = [
            "data_name",            
        ]

But for some reason in the JSON I have data_json.form.content = '2024-24' but elastic defined this field as Date. So I get an exception during the indexing.
I wanted to define a specific mapping for this and my idea was to add a class Meta into my MyDataDocument, something like this :

class Meta:
        mapping = {
            "properties": {
                "data_json": {
                    "properties": {
                        "form": {
                            "properties": {
                                "content": {
                                      "type": "text",
                                       "fields": {
                                              "keyword": {
                                                  "type": "keyword",
                                                  "ignore_above": 256
                                               }                                    
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

But it does not work like this. Is it possible to define it in the Document Class ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions