Update field

Is there a way (using the Java API) to update a field without having
to re-send all the other fields in the document?

You are a lucky the update API has just been commited in master branch and
will be available in the next released version.

Have a look here for more information:

Thanks. In the meantime, will this work?

Suppose I have a SearchHit object resulting from a search, and I use
sourceAsMap to get the source as a map:

Map<String,Object> source = hit.sourceAsMap();

Then I modify the map in some way:

source.put("somefield", "someUpdatedValue");

Then I re-index the source:

client.prepareIndex("myIndex", "myType",
hit.id()).setSource(source).setOpType(OpType.INDEX).execute();

Will this correctly re-index the document with the new value?
Specifically, is there any danger that in doing this, I might lose
something that was previously part of the document (perhaps, a field
that was indexed but not stored)?

Thanks,
Frank

On Jan 6, 5:54 pm, Benjamin Devèze benjamin.dev...@gmail.com wrote:

You are a lucky the update API has just been commited in master branch and
will be available in the next released version.

Have a look here for more information:Update API: Allow to update a document based on a script · Issue #1583 · elastic/elasticsearch · GitHub

Yes, that would work. Note, you might want to use versioning to make sure
an update did not happen in the meantime. When you search, specify that you
want to get versions back (SearchRequestBuilder#setVersion(true)), and then
index the document with the version you get. If there was an update while
it happened, you will get a version conflict failure.

On Mon, Jan 9, 2012 at 7:09 PM, Frank LaRosa frank@studyblue.com wrote:

Thanks. In the meantime, will this work?

Suppose I have a SearchHit object resulting from a search, and I use
sourceAsMap to get the source as a map:

Map<String,Object> source = hit.sourceAsMap();

Then I modify the map in some way:

source.put("somefield", "someUpdatedValue");

Then I re-index the source:

client.prepareIndex("myIndex", "myType",
hit.id()).setSource(source).setOpType(OpType.INDEX).execute();

Will this correctly re-index the document with the new value?
Specifically, is there any danger that in doing this, I might lose
something that was previously part of the document (perhaps, a field
that was indexed but not stored)?

Thanks,
Frank

On Jan 6, 5:54 pm, Benjamin Devèze benjamin.dev...@gmail.com wrote:

You are a lucky the update API has just been commited in master branch
and
will be available in the next released version.

Have a look here for more information:
Update API: Allow to update a document based on a script · Issue #1583 · elastic/elasticsearch · GitHub

Great, thanks for the response. I'll add the version number, too.

If there's a version conflict, will it be thrown immediately by
client.prepareIndex(..).execute(), or do I need to call actionGet() to
examine the response?

On Jan 9, 1:32 pm, Shay Banon kim...@gmail.com wrote:

Yes, that would work. Note, you might want to use versioning to make sure
an update did not happen in the meantime. When you search, specify that you
want to get versions back (SearchRequestBuilder#setVersion(true)), and then
index the document with the version you get. If there was an update while
it happened, you will get a version conflict failure.

On Mon, Jan 9, 2012 at 7:09 PM, Frank LaRosa fr...@studyblue.com wrote:

Thanks. In the meantime, will this work?

Suppose I have a SearchHit object resulting from a search, and I use
sourceAsMap to get the source as a map:

Map<String,Object> source = hit.sourceAsMap();

Then I modify the map in some way:

source.put("somefield", "someUpdatedValue");

Then I re-index the source:

client.prepareIndex("myIndex", "myType",
hit.id()).setSource(source).setOpType(OpType.INDEX).execute();

Will this correctly re-index the document with the new value?
Specifically, is there any danger that in doing this, I might lose
something that was previously part of the document (perhaps, a field
that was indexed but not stored)?

Thanks,
Frank

On Jan 6, 5:54 pm, Benjamin Devèze benjamin.dev...@gmail.com wrote:

You are a lucky the update API has just been commited in master branch
and
will be available in the next released version.

Have a look here for more information:
Update API: Allow to update a document based on a script · Issue #1583 · elastic/elasticsearch · GitHub

execute just executes the operation, you get back a future to actually get
the response / exception, so yes, you need to call get to know what
happened.

On Mon, Jan 9, 2012 at 10:22 PM, Frank LaRosa frank@studyblue.com wrote:

Great, thanks for the response. I'll add the version number, too.

If there's a version conflict, will it be thrown immediately by
client.prepareIndex(..).execute(), or do I need to call actionGet() to
examine the response?

On Jan 9, 1:32 pm, Shay Banon kim...@gmail.com wrote:

Yes, that would work. Note, you might want to use versioning to make sure
an update did not happen in the meantime. When you search, specify that
you
want to get versions back (SearchRequestBuilder#setVersion(true)), and
then
index the document with the version you get. If there was an update while
it happened, you will get a version conflict failure.

On Mon, Jan 9, 2012 at 7:09 PM, Frank LaRosa fr...@studyblue.com
wrote:

Thanks. In the meantime, will this work?

Suppose I have a SearchHit object resulting from a search, and I use
sourceAsMap to get the source as a map:

Map<String,Object> source = hit.sourceAsMap();

Then I modify the map in some way:

source.put("somefield", "someUpdatedValue");

Then I re-index the source:

client.prepareIndex("myIndex", "myType",
hit.id()).setSource(source).setOpType(OpType.INDEX).execute();

Will this correctly re-index the document with the new value?
Specifically, is there any danger that in doing this, I might lose
something that was previously part of the document (perhaps, a field
that was indexed but not stored)?

Thanks,
Frank

On Jan 6, 5:54 pm, Benjamin Devèze benjamin.dev...@gmail.com wrote:

You are a lucky the update API has just been commited in master
branch
and
will be available in the next released version.

Have a look here for more information:
Update API: Allow to update a document based on a script · Issue #1583 · elastic/elasticsearch · GitHub

I'm having some trouble. Sometimes it works, and other times it throws
the VersionConflictEngineException.

I suspect this is happening because in my initial test case I'm simply
trying to update the same document several times in a tight loop. I
can see how this might cause version conflicts in a true distributed
environment, although I'm not sure why it does even in my test
environment which only has one server.

I tried to solve the problem by
adding .setConsistencyLevel(WriteConsistencyLevel.ALL) to my write
operation. However, this causes the write operation to hang
indefinitely for some reason.

Any suggestion as to what else I can do here?

On Jan 9, 3:09 pm, Shay Banon kim...@gmail.com wrote:

execute just executes the operation, you get back a future to actually get
the response / exception, so yes, you need to call get to know what
happened.

On Mon, Jan 9, 2012 at 10:22 PM, Frank LaRosa fr...@studyblue.com wrote:

Great, thanks for the response. I'll add the version number, too.

If there's a version conflict, will it be thrown immediately by
client.prepareIndex(..).execute(), or do I need to call actionGet() to
examine the response?

On Jan 9, 1:32 pm, Shay Banon kim...@gmail.com wrote:

Yes, that would work. Note, you might want to use versioning to make sure
an update did not happen in the meantime. When you search, specify that
you
want to get versions back (SearchRequestBuilder#setVersion(true)), and
then
index the document with the version you get. If there was an update while
it happened, you will get a version conflict failure.

On Mon, Jan 9, 2012 at 7:09 PM, Frank LaRosa fr...@studyblue.com
wrote:

Thanks. In the meantime, will this work?

Suppose I have a SearchHit object resulting from a search, and I use
sourceAsMap to get the source as a map:

Map<String,Object> source = hit.sourceAsMap();

Then I modify the map in some way:

source.put("somefield", "someUpdatedValue");

Then I re-index the source:

client.prepareIndex("myIndex", "myType",
hit.id()).setSource(source).setOpType(OpType.INDEX).execute();

Will this correctly re-index the document with the new value?
Specifically, is there any danger that in doing this, I might lose
something that was previously part of the document (perhaps, a field
that was indexed but not stored)?

Thanks,
Frank

On Jan 6, 5:54 pm, Benjamin Devèze benjamin.dev...@gmail.com wrote:

You are a lucky the update API has just been commited in master
branch
and
will be available in the next released version.

Have a look here for more information:
Update API: Allow to update a document based on a script · Issue #1583 · elastic/elasticsearch · GitHub

Note, even if you have a single thread doing search / update, the index is
refreshed every 1 second to have changes visible for search, so, if you
search, you might get "stale" values. If you did "get" and then "index"
(thanks to realtime get), you will always get the latest value of the
document.

On Mon, Jan 9, 2012 at 11:53 PM, Frank LaRosa frank@studyblue.com wrote:

I'm having some trouble. Sometimes it works, and other times it throws
the VersionConflictEngineException.

I suspect this is happening because in my initial test case I'm simply
trying to update the same document several times in a tight loop. I
can see how this might cause version conflicts in a true distributed
environment, although I'm not sure why it does even in my test
environment which only has one server.

I tried to solve the problem by
adding .setConsistencyLevel(WriteConsistencyLevel.ALL) to my write
operation. However, this causes the write operation to hang
indefinitely for some reason.

Any suggestion as to what else I can do here?

On Jan 9, 3:09 pm, Shay Banon kim...@gmail.com wrote:

execute just executes the operation, you get back a future to actually
get
the response / exception, so yes, you need to call get to know what
happened.

On Mon, Jan 9, 2012 at 10:22 PM, Frank LaRosa fr...@studyblue.com
wrote:

Great, thanks for the response. I'll add the version number, too.

If there's a version conflict, will it be thrown immediately by
client.prepareIndex(..).execute(), or do I need to call actionGet() to
examine the response?

On Jan 9, 1:32 pm, Shay Banon kim...@gmail.com wrote:

Yes, that would work. Note, you might want to use versioning to make
sure
an update did not happen in the meantime. When you search, specify
that
you
want to get versions back (SearchRequestBuilder#setVersion(true)),
and
then
index the document with the version you get. If there was an update
while
it happened, you will get a version conflict failure.

On Mon, Jan 9, 2012 at 7:09 PM, Frank LaRosa fr...@studyblue.com
wrote:

Thanks. In the meantime, will this work?

Suppose I have a SearchHit object resulting from a search, and I
use
sourceAsMap to get the source as a map:

Map<String,Object> source = hit.sourceAsMap();

Then I modify the map in some way:

source.put("somefield", "someUpdatedValue");

Then I re-index the source:

client.prepareIndex("myIndex", "myType",
hit.id()).setSource(source).setOpType(OpType.INDEX).execute();

Will this correctly re-index the document with the new value?
Specifically, is there any danger that in doing this, I might lose
something that was previously part of the document (perhaps, a
field
that was indexed but not stored)?

Thanks,
Frank

On Jan 6, 5:54 pm, Benjamin Devèze benjamin.dev...@gmail.com
wrote:

You are a lucky the update API has just been commited in master
branch
and
will be available in the next released version.

Have a look here for more information:
Update API: Allow to update a document based on a script · Issue #1583 · elastic/elasticsearch · GitHub