JAVA API Field level control on index (store and index settings)

(vishal_hm) #1

We have just started evaluating elastic search.
We already did a POC on Lucene, and now evaluating elastic search for deployment in clustered environment.

Now given below is some generic code example from our Lucene implementation.

Document aDocument = new Document();
aDocument.add(new Field("F1","content1",Field.Store.YES,Field.Index.NOT_ANALYZED_NO_NORMS));
aDocument.add(new Field("F2","content2",Field.Store.YES,Field.Index.ANALYZED));
aDocument.add(new Field("F3",content,Field.Store.NO,Field.Index.ANALYZED_NO_NORMS));
aDocument.add(new Field("F4",content,Field.Store.YES,Field.Index.NO));
At last,


Now We need to migrate same to ES. For us preferred way of interaction would be JAVA API.

Now my current ES code structure for index creation is as follows,

CreateIndexRequest createRequest = new CreateIndexRequest(indexName);

Builder settingsBuilder = ImmutableSettings.settingsBuilder();
settingsBuilder=settingsBuilder.put("number_of_shards", 2);
settingsBuilder=settingsBuilder.put("number_of_replicas", 1);
Settings indexSettings =;

//createRequest=createRequest.mapping(arg0, arg1);

///Code for adding objects into index

BulkRequestBuilder brb = client.prepareBulk();

for (MyClass anObj: objList ) {

brb.add(client.prepareIndex(indexName, "default_type",anObj.getId)

BulkResponse bResponse = brb.execute().actionGet();

Kindly suggest Where I need to specify the mappings in Java API.

From REST API example I got this link from documentation.

I need exactly this from Java API.

Thanks in advance,

(system) #2