Question: I have an index with the name 'dev-steps', 

mapping for this index:

```
    {
        "dev-steps": {
          "mappings": {
            "steps": {
              "properties": {
                "cId": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
                "data": {
                  "properties": {
                    "ui034": {
                        "type": "long"
                    },
                    "ksms5": {
                        "type": "long"
                    },
                    "ui0tg": {
                        "type": "long"
                    },
                    "vcw5d": {
                        "type": "long"
                    }
                  }
                },
                "uId": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                }
              }
            }
          }
        }
      }

```

I see a problem, any time when I add new value to the field 'data', that add a new property to the mapping; how I can create a dynamic mapping?

Answer: 
Objects with static storage duration have two phases of initialisation: Static phase and dynamic phase. Some static variables don't have dynamic initialisation at all. Those objects that do have dynamic initialisation are initially statically zero-initialised.

The static phase of initialisation happens when the program starts, before anything else. Thus, memory must also have been allocated before anything else.

The dynamic phase of initialisation cannot be instantaneous. Dynamic initialisation may have dependencies on initialisation of other static objects. Some objects are necessarily initialised before other objects. This is why dynamic initialisation happens after allocation.

For namespace scope variables with static storage, their dynamic initialisation happens either before `main`, or it may be deferred later in which case it happens before anything from that same translation unit is accessed or called (in practice, deferral happens when dynamic loading is involved).

For static local variables...

> 
> Static variables in a function are initialized before the function is called for the first time
> 
> 
> 

Not exactly. Their dynamic initialisation always happens exactly when execution reaches them for the first time. That is always *after* the function is called; not before. For example:

```
void foo(bool bar)
{
    if (bar) {
        static T var;
    }
}

```

`var` will not be initialised even when the function is called, if the provided argument is `false`.

The order of dynamic initialisation across translation units is unspecified. This would otherwise make it impossible to safely rely on initialisation of objects with static storage from other translation units, but the "initialisation on first use" behaviour of static local variables is a feature that allows exact control over the order of their initialisation, making it possible to rely on their initialisation even across translation unit boundaries.
I think, based on your comments, that the detail you are missing is that there are both global and local static variables.

Global static variables are initialized when the program is first loaded. Edit: Apparently this is not required behavior (though it is the most common) - initialization is allowed to be delayed. See comment by @walnut.

Example:

```
int main()
{
    std::cout << "start program!" << std::endl;
    return 0;
}

static Base b;

```

Output:

```
I'm Base
start program!

```

While static variables in functions are initialized the first time control passes over them. Example:

```
int main()
{
    std::cout << "start program!" << std::endl;
    static Base b;
    return 0;
}

```

Output:

```
start program!
I'm Base

```

I have added a second example, as per @EvilTeach's comment, to show how the static is only initialized a single time despite multiple functioncalls. Also, added guard (from @eerorika's answer) to show how initialization only happens when execution actually reaches the variable.

```
void testFunc(bool test)
{
    std::cout << "testFunc called with: " << test << std::endl;
    if (test)
        static Base b;
}

int main()
{
    testFunc(false);
    testFunc(true);
    testFunc(true);
    return 0;
}

```

Output:

```
testFunc called with: 0
testFunc called with: 1
I'm Base
testFunc called with: 1

```