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


(vishal_hm) #1

Hi,
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,

IndexConfig.getIndexwriter().addDocument(doc);

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 = settingsBuilder.build();

createRequest.settings(indexSettings);
//?
//createRequest=createRequest.mapping(arg0, arg1);
client.admin().indices().create(createRequest).actionGet();

///Code for adding objects into index
//

BulkRequestBuilder brb = client.prepareBulk();

for (MyClass anObj: objList ) {

brb.add(client.prepareIndex(indexName, "default_type",anObj.getId)
.setSource(convertToJSON(anObj)));
}

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.

http://www.elasticsearch.org/guide/reference/java-api/bulk.html

I need exactly this from Java API.

Thanks in advance,
Vishal.


(system) #2