Skip to content

Instantly share code, notes, and snippets.

@nz
Created February 23, 2012 16:42
Show Gist options
  • Save nz/1893682 to your computer and use it in GitHub Desktop.
Save nz/1893682 to your computer and use it in GitHub Desktop.
Setting a mapping for all types in an index, where types are unknown

Question: is it possible to set a mapping for all types in an index?

I am attempting to apply a default _ttl to all types in an index, without knowing the various types in advance.

The docs show plenty of examples where a mapping is given for a specific type. But there is no indication of how to

What I've tried

Attempt 1: key with _all

curl -XPUT http://localhost:9200/testing23feb12 -d '{
  "settings": {
    "number_of_shards":1
  },
  "mapping": {
    "_all": {
      "_ttl":{"enabled":true}
    }
  }
}'
{"ok":true,"acknowledged":true}

Didn't seem to work:

[2012-02-23 09:34:15,939][INFO ][cluster.metadata         ] [Brothers Grimm] [testing23feb12] creating index, cause [api], shards [1]/[1], mappings []

Attempt 2: key with _default_

curl -XPUT http://localhost:9200/testing23feb12-2 -d '{
  "settings": {
    "number_of_shards":1
  },
  "mapping": {
    "_default_": {
      "_ttl":{"enabled":true}
    }
  }
}'

Didn't work:

[2012-02-23 09:40:32,051][INFO ][cluster.metadata         ] [Brothers Grimm] [testing23feb12-2] creating index, cause [api], shards [1]/[1], mappings []

Attempt 3: spell it right, yo

clintongormley> mapping should be plural

curl -XPUT http://localhost:9200/testing23feb12-3 -d '{
  "settings": {
    "number_of_shards":1
  },
  "mappings": {
    "_default_": {
      "_ttl":{"enabled":true}
    }
  }
}'

Victory:

[2012-02-23 09:44:27,393][INFO ][cluster.metadata         ] [Brothers Grimm] [testing23feb12-3] creating index, cause [api], shards [1]/[1], mappings [_default_]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment