0

I have to create mapping which should look something like this.

{
  "mappings": {
    "properties": {
        "product_id": {
            "type": "keyword"
        },
        "attributes": {
            "dynamic": "true",
            "properties": {}
        },
    }
}   

I would normally do something like this

class RetailerProductGeneric(Document):
    product_id = Keyword()
    

how do I do it when I have a dynamic schema in the document ?

I looked at the docs but not very clear to me. It goes as follows:

class Post(Document):
    title = Text()

    class Meta:
        all = MetaField(enabled=False)
        dynamic = MetaField('strict')

not sure what is happening here. Can someone please explain how to do it?

EDIT 1:

After some research, I figured how to create the dynamic mapping.

class RetailerProductGeneric(Document):
    product_id = Keyword()
    attributes = Object(dynamic=True)

but now expected mapping turns out to be like this

  "attributes": {
    "dynamic": true,
    "type": "object"
  },

what I am looking for is

  "attributes": {
    "dynamic": "true",
    "properties": {}
  },

What difference does it make? How Can I make the mapping as expected.

6
  • What additional information do you need that isn't already contained in the answer? Commented Jun 29, 2021 at 6:54
  • I think I am good. Thanks a lot :) @Val Commented Jun 29, 2021 at 13:39
  • May I ask why you added the bounty to draw more attention then? Commented Jun 29, 2021 at 13:42
  • Actually, how to get the dynamic template mapping was my original question, which I eventually figured out. Later I was confused about a part that you answered. since I dint get any response in first 2 days, I started bounty. Commented Jun 29, 2021 at 13:45
  • 1
    Thanks again, feel free to create a new question if more information is needed ;-) Commented Jun 29, 2021 at 20:04

1 Answer 1

1
+50

Good start!!

"attributes": {
  "dynamic": true,
  "type": "object"
},

and

"attributes": {
  "dynamic": "true",
  "properties": {}
},

are actually exactly the same thing.

When type: object is specified, properties: {} is implied

And when properties: {} is specified and no type is given, then type: object is implied.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.