Skip to content

Instantly share code, notes, and snippets.

@TimSin
TimSin / gist:6154882
Created August 5, 2013 10:16
Elasticsearch Java create mapping
Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress(
"localhost", 9300));
XContentBuilder mapping = XContentFactory.jsonBuilder()
.startObject()
.startObject("mappings")
.startObject("testobject")
.startObject("properties")
.startObject("key")
.field("type", "string")
@TimSin
TimSin / gist:6156670
Created August 5, 2013 15:09
Setting elasticsearch index and mapping settings using the java API
XContentBuilder settings = // ...create settings JSON object
XContentBuilder mapping = // ...build mapping JSON object
CreateIndexRequestBuilder irb = client.admin().indices().prepareCreate(INDEX_NAME);
irb.setSettings(settings);
irb.execute().actionGet();
PutMappingResponse response = client.admin().indices()
.preparePutMapping(INDEX_NAME).setType(TYPE_NAME)