Update Api in java

Hello Everyone,

I wanted to update some of my indexed data with a particular id using Java
Api.
I came to know that I can update using any script.

My question is: Can we only update using script? Any sample code for this..?
Can I simply update value of any already indexed field?

Thanks in advance..!!

Hi Ajasuja,

My question is: Can we only update using script? Any sample code for this..?
Can I simply update value of any already indexed field?
As far as I know script is the only way to update a document. As long
as the _source of document is stored you can update any field of
document.

Example showing how to update a title field:
Node node = nodeBuilder().client(true).node();
Client client = node.client();
String index = "my_index";
String type= "my_type";
String id = "1";
String newTitle = "my new title";
client.prepareUpdate(index, type, id)
.setScript("ctx._source.title="" + newTitle + """)
.execute()
.actionGet();

Martijn

Thanks Martijn. It works for me .. thanks alot.

I hava one more question if you can help me in this.

In elasticsearch, as we know, while querying we can give various aspects of
querying.
One category is Query_and_fetch v/s Query_then_fetch.
Also one more add on we can provide is the dfs query with both of them.

I heard one of the vedio of Shay Banon explaining dfs query and he
mentioned that
in case of dfs, there is an additional phase in which frequencies from all
the shards
is gathered.

*I am not sure what he means by frequencies. Is it just the distributed
term frequencies *
*or it also takes into account the distributed inverse document frequencies?
*

Thanks in advance.

On Monday, July 30, 2012 3:46:38 AM UTC-7, Martijn v Groningen wrote:

Hi Ajasuja,

My question is: Can we only update using script? Any sample code for
this..?
Can I simply update value of any already indexed field?
As far as I know script is the only way to update a document. As long
as the _source of document is stored you can update any field of
document.

Example showing how to update a title field:
Node node = nodeBuilder().client(true).node();
Client client = node.client();
String index = "my_index";
String type= "my_type";
String id = "1";
String newTitle = "my new title";
client.prepareUpdate(index, type, id)
.setScript("ctx._source.title="" + newTitle + """)
.execute()
.actionGet();

Martijn

The dfs phase helps with computing more accurate scores.
In the dfs phase on each shard for all terms that match the query the
document frequency is computed.
Each dfs shard result is merged and the merged result is used as input
for the idf part of the score computing in the
query phase.

Martijn

On 30 July 2012 20:47, ajasuja jasuja.ankit@gmail.com wrote:

Thanks Martijn. It works for me .. thanks alot.

I hava one more question if you can help me in this.

In elasticsearch, as we know, while querying we can give various aspects of
querying.
One category is Query_and_fetch v/s Query_then_fetch.
Also one more add on we can provide is the dfs query with both of them.

I heard one of the vedio of Shay Banon explaining dfs query and he mentioned
that
in case of dfs, there is an additional phase in which frequencies from all
the shards
is gathered.

I am not sure what he means by frequencies. Is it just the distributed term
frequencies
or it also takes into account the distributed inverse document frequencies?

Thanks in advance.

On Monday, July 30, 2012 3:46:38 AM UTC-7, Martijn v Groningen wrote:

Hi Ajasuja,

My question is: Can we only update using script? Any sample code for
this..?
Can I simply update value of any already indexed field?
As far as I know script is the only way to update a document. As long
as the _source of document is stored you can update any field of
document.

Example showing how to update a title field:
Node node = nodeBuilder().client(true).node();
Client client = node.client();
String index = "my_index";
String type= "my_type";
String id = "1";
String newTitle = "my new title";
client.prepareUpdate(index, type, id)
.setScript("ctx._source.title="" + newTitle + """)
.execute()
.actionGet();

Martijn