4

Use case :

  1. The index/indices will be built dynamically from a template, so that it will pick some custom settings (number of shards/replicas/ etc).
  2. Generate dynamically the types and their mappings, enabling for them all the timestamp & ttl fields. Also define the same parent type for all types, except the parent type itself (I know its name).

    {
       "template": "*",
    
       "settings": {
          ...................
       },
    
       "mappings": {
    
          "_default_": {
             "_parent": {
                "type": "ParentType"
             },
             "_timestamp": {
                "enabled": true,
                "store": true
             },
             "_ttl": {
                "enabled": true
             }
          }
    
       }
    }
    

How could I disable the _parent field for the ParentType type itself ?

1 Answer 1

1

After a little big of digging on the docs, I found out that you can override __default__ mappings using this work around.

{
   "mappings": {
      "_default_": {
         "_parent": {
             "type": "my_parent_type" # 1
         }
      },
      "my_parent_type": {
          "_parent": {
              "type": "_dummy" # 2
          }
      }
   }
}

1) This mapping configuration will be inherited by all your types including my_parent_typetype. Step 2 explains how to override your parent type _parent meta-field.

2) I found here https://www.elastic.co/guide/en/elasticsearch/reference/current/default-mapping.html that you can override any of the mappings from __default__ when you provide a specific mapping for the type in question.

In this case we are assigning the _parent mapping of my_parent_type to a _dummy parent type that does not have to exists in your index.

Note: ElasticSearch 2.x documentation states:

The _parent.type setting can only point to a type that doesn’t exist yet. This means that a type cannot become a parent type after it is has been created.

For this reason, you have to make sure you index first, a document that is not my_parent_type type, otherwise you'll get an at indexing time.

I hope this helps.

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

1 Comment

But when index parent document you still require ?parent=, if not you will get error. Right now I am using a dummy value nil for _parent field, I don't know if it bad for performent or not.And sometime misleading too . Is there a way remove it ?

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.