Using Java API's prepareUpdate

I currently use prepareIndex to index a document like this:

idxResponse =

client.prepareIndex(indexName, indexType, id)

.setSource(json)

.execute()

.actionGet();

I am trying to use setSource(json) with prepareUpdate but that doesn't seem
to work. Is there some other alternative that I can use?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAOT3TWpZbF2jQwfKZmb5_BN%2BvFSd7c0aRhzEPSDQPH80E_iK9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Here is my code for the INDEX action. Similar code (not shown) exists for
the CREATE action. This is for ES 1.0.0 GA, though it hasn't changed since
its 0.90.X versions:

IndexResponse response = null;
try
{
IndexRequestBuilder irb = client.prepareIndex(index, type, id);
irb.setSource(json).setOpType(IndexRequest.OpType.INDEX);
irb.setRefresh(refresh);

/* Set the version number and version type (internal or external) */
if (rec.hasVersion())
{
irb.setVersion(rec.getVersion());
if (rec.isVersionExternal())
irb.setVersionType(VersionType.EXTERNAL);
}

/* Set the TTL (time to live) if there is one */
TimeValue ttl = rec.getTTL();
if (ttl != null)
irb.setTTL(ttl.getMillis());

response = irb.execute().actionGet();
}
catch (Exception e)
{
...
}

Don't worry about rec. It's just a class that generically describes the
documents and contains various attributes and field values, and can
serialize itself to JSON.

Hope this helps.

Brian

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/c26e586f-3df5-4c22-b239-42dc614bf9af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thanks does it create a new index if it doesn't exist?

On Tue, Mar 18, 2014 at 12:35 PM, InquiringMind brian.from.fl@gmail.comwrote:

Here is my code for the INDEX action. Similar code (not shown) exists for
the CREATE action. This is for ES 1.0.0 GA, though it hasn't changed since
its 0.90.X versions:

IndexResponse response = null;
try
{
IndexRequestBuilder irb = client.prepareIndex(index, type, id);
irb.setSource(json).setOpType(IndexRequest.OpType.INDEX);
irb.setRefresh(refresh);

/* Set the version number and version type (internal or external) */
if (rec.hasVersion())
{
irb.setVersion(rec.getVersion());
if (rec.isVersionExternal())
irb.setVersionType(VersionType.EXTERNAL);
}

/* Set the TTL (time to live) if there is one */
TimeValue ttl = rec.getTTL();
if (ttl != null)
irb.setTTL(ttl.getMillis());

response = irb.execute().actionGet();
}
catch (Exception e)
{
...
}

Don't worry about rec. It's just a class that generically describes the
documents and contains various attributes and field values, and can
serialize itself to JSON.

Hope this helps.

Brian

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/c26e586f-3df5-4c22-b239-42dc614bf9af%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/c26e586f-3df5-4c22-b239-42dc614bf9af%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAOT3TWq6fcUJNs26X%2BovxsJOvB5kjjTcSOU_ehttj%2BEUWnf6Ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

  1. By default, it creates an index if the index does not exist. But no, it
    won't create an index if the index does not exist and the following is in
    your elsasticsearch.yml configuration:

action.auto_create_index: false

  1. But did you mean: Does it create a document if the document does not
    exist? If so, then yes: The index action updates the document if it exists
    but creates the document if it does not exist.

The create action fails if the document already exists.

  1. I deleted my first post because I realized that it didn't answer your
    question: I wasn't using prepareUpdate and actually have no experience with
    that particular API action. Sorry for any confusion I may have caused.

I hope this helps.

Brian

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/0819f28a-0417-4727-b7d1-90b5927439bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.