Skip to content

Instantly share code, notes, and snippets.

@dggc
Created September 11, 2013 13:15
Show Gist options
  • Save dggc/6523411 to your computer and use it in GitHub Desktop.
Save dggc/6523411 to your computer and use it in GitHub Desktop.
Code to create the mappings in Java
client.admin().indices().prepareCreate(source.toString().toLowerCase()).execute().actionGet();
XContentBuilder xbMapping = XContentFactory.jsonBuilder().startObject().startObject("documents");
xbMapping.startObject(ELASTIC_TTL).field("enabled", true).field("default", (30*60*1000)+"ms").endObject();
xbMapping.startObject("properties");
xbMapping.startObject("content").field("type", "string").endObject();
xbMapping.startObject("insertedDate").field("type", "long").endObject();
xbMapping.endObject();
xbMapping.endObject().endObject();
client.admin().indices().preparePutMapping("documents").setType("documents").setSource(xbMapping).execute().actionGet();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment