1

I need to create the dynamic mapping for unknown new fields in the index using a dynamic template. My sample mapping is:

{  
   "indexname":{  
      "dynamic_templates":[  
         {  
            "template_1":{  
               "match":"*",
               "dynamic fields":{  
                  "type":"dynamictype",
                  "index":"not_analyzed"
               }
            }
         }
      ]
   }
}

I'm little bit confused to create the dynamic mapping is anyone kindly guide me to solve this.

i want to create the mapping multiple fields during the run time using java API is any one to guide me.

1 Answer 1

1

Follow this :

 {
      "dynamic_templates": [
        {
          "template_1": {
            "path_match": "*",
            "mapping": {
              "index": "not_analyzed",
              "type": "string"
            }
          }
        }
      ]
    }

and I am not pretty sure about the 'dynamictype' in your code. You have to specify an exact type.

edit :

{
  "dynamic_templates": [
    {
      "dynamic_1": {
        "path_match": "abcd*",
        "mapping": {
          "include_in_all": true,
          "index": "not_analyzed",
          "type": "string"
        }
      }
    },
    {
      "dynamic_2": {
        "path_match": "address.phone.*",
        "mapping": {
          "include_in_all": true,
          "type": "long"
        }
      }
    }
  ]
}

The first one(named template_1) will be applied to all new fields starting with 'abcd' and second (named template_2) will be applied to all nested fields with in 'phone' which is already nested in 'address' field.

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

3 Comments

thanks for ur response i already tried this i want to create the mapping for multiple fields during i had no idea about it can u guid me to do that using java api
you should have a slight clue about the path of the fields for specifying different mappings for multiple fields. Otherwise you can use a wild card and specify a single template as in the first example. see my edits.
thanks for your response after i using the example you mentioned above i faced the Root type mapping not empty after parsing! error it is not worked expectedly can you guide me to fix 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.