1

I don't seem to understand how to prevent elasticsearch from automatically adding new mappings for new fields. The documentation states

Automatic type creation can also be disabled for all indices by setting an index template:

PUT _template/template_all
{
  "template": "*",
  "order":0,
  "settings": {
    "index.mapper.dynamic": false 
  }
}

So this is what I am doing:

client.admin().indices()
    .preparePutTemplate("template_disable_dynamic_mapping")
    .setTemplate("*")
    .setSettings(Settings.builder().put("index.mapper.dynamic", false))
    .get();

and after creating an index with a custom mapping for data, I can see these mappings and setting, GET /data/_settings returns:

{
  "data": {
    "mappings": {
      "some_type": {
        "properties": {
          "value": {
            "type": "text"
          },
          [...]
        }
      }
    }
  },
  "settings": {
    "index": {
      "mapper": {
        "dynamic": "false"
      },
      [...]
    }
  }
}

Now if I index a document with a new field foo, it gets inserted successfully and my new mapping looks like this: GET /data/_mapping

{
  "data": {
    "mappings": {
      "some_type": {
        "properties": {
          "foo": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "value": {
            "type": "text"
          },
          [...]
        }
      }
    }
  }
}

My expectation was that no new mapping would be created.

Felk
  • 7,720
  • 2
  • 35
  • 65
  • Are you sure the template was saved properly (the way you expected it to be)? Check the list of templates with `GET /_template`. – Andrei Stefan May 02 '17 at 11:41
  • @Andrei Stefan The template exists exactly as expected. @halileohalilei thanks, following that question I was able to solve it by setting the mapping's `dynamic` to `strict` – Felk May 02 '17 at 11:50

0 Answers0