Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a mapping on the Document class #475

Open
pulse-mind opened this issue Feb 5, 2024 · 1 comment
Open

How to add a mapping on the Document class #475

pulse-mind opened this issue Feb 5, 2024 · 1 comment

Comments

@pulse-mind
Copy link

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 ?

@pulse-mind
Copy link
Author

It seems to work with :

data_json = fields.ObjectField(
        properties={
            "form": fields.ObjectField(
                properties={
                    "content": fields.TextField()
                                                }
                                            )
                                        }
                                    )
     

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant