I want to disable the source with Java API (for a pre-existing index before setting a new ID)

Hey elasticsearch community,

I'm extremely new to the elasticsearch world. Three days to be exact. I have been given a project that uses elasticsearch, and I've been stuck with trying to disable storing the source via Java API. I've googled and looked at many topics in the forums for many hours to no avail. My problem seems to be very specific:

  1. I already have an index and type declared.
  2. I have already indexed a couple items prior.
  3. I have recently added a new field that holds a large amount of text.
  4. Therefore, I want to set _source enabled to false, so that the database usage is conserved.
  5. I want to do all of this in one Java method.

Below is a Java method that is called when a user posts a new item. The purpose of the method is to index the fields of the item into elasticsearch. Currently, the method defines no settings or mappings. It just clumps all the POST data and throws it into the index. I want to change the method to set _source:enabled to false as shown here: http://www.elasticsearch.org/guide/reference/mapping/source-field.html

public void index(final int id, final T model) {
final IndexResponse response = client
.prepareIndex(
"myIndexName",
"myTypeName"
)
.setId(id)
.setSource(objectWriter.writeValueAsBytes(model))
.execute()
.actionGet();
}

(Note: the client variable is previously set when the object is declared.)

So my question boils down to:

How do I disable the source within the index function?

I would like valid code where I can basically c/p it onto my code and replace it with the real index, type, and id names. I would greatly appreciate the help! Any help, really. I've tried many approaches, and all have failed.

Thank you!

  • Elfrey, elasticsearch newbie