Insert if not exists

hi,
my use case is something like this: i m inserting some data using auto
id generation. so in future i' don't know what the id it created.
now if i have to
insert some field in that doc, i have to search for previous fields and
update that doc.
i can do it using two queries search and if not exists then update.
BUT my question is --> is there any way i can do it in one
query??????

thanks,
subhankar

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Just see
Operation Type in http://www.elasticsearch.org/guide/reference/api/index_/

HTH

Thanks
Vineeth
On Wed, May 8, 2013 at 5:36 PM, subhankar neo20iitkgp@gmail.com wrote:

hi,
my use case is something like this: i m inserting some data using auto
id generation. so in future i' don't know what the id it created.
now if i have to
insert some field in that doc, i have to search for previous fields and
update that doc.
i can do it using two queries search and if not exists then update.
BUT my question is --> is there any way i can do it in one
query??????

thanks,
subhankar

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

hi vineeth,
i m very new to ES. i saw that earlier.
plz correct me if i am wrong. i think that is for index request. for
update api how this will work. i have to combine the query and update api
both.
and i think https://github.com/yakaz/elasticsearch-action-updatebyquery will
satisfy the requirement. what do you think. can you please give me a small
example ??

Thanks,
subhankar

On Wednesday, 8 May 2013 18:05:13 UTC+5:30, Vineeth Mohan wrote:

Just see
Operation Type in http://www.elasticsearch.org/guide/reference/api/index_/

HTH

Thanks
Vineeth
On Wed, May 8, 2013 at 5:36 PM, subhankar <neo20...@gmail.com<javascript:>

wrote:

hi,
my use case is something like this: i m inserting some data using
auto id generation. so in future i' don't know what the id it created.
now if i have to
insert some field in that doc, i have to search for previous fields and
update that doc.
i can do it using two queries search and if not exists then
update.
BUT my question is --> is there any way i can do it in one
query??????

thanks,
subhankar

--
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 elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

This plugin is to update all existing documents by query. So if the
document does not exist , it wont do anything.
I believe what you need is "UPDATE IF EXISTS" , "CREATE IF NOT EXISTS"
AFAIK this cant be done in a single query (And hence not atomic)

Thanks
Vineeth

On Wed, May 8, 2013 at 6:24 PM, subhankar neo20iitkgp@gmail.com wrote:

hi vineeth,
i m very new to ES. i saw that earlier.
plz correct me if i am wrong. i think that is for index request. for
update api how this will work. i have to combine the query and update api
both.
and i think
https://github.com/yakaz/elasticsearch-action-updatebyquery will satisfy
the requirement. what do you think. can you please give me a small example
??

Thanks,
subhankar

On Wednesday, 8 May 2013 18:05:13 UTC+5:30, Vineeth Mohan wrote:

Just see
Operation Type in http://www.elasticsearch.org/**
guide/reference/api/index_/http://www.elasticsearch.org/guide/reference/api/index_/

HTH

Thanks
Vineeth
On Wed, May 8, 2013 at 5:36 PM, subhankar neo20...@gmail.com wrote:

hi,
my use case is something like this: i m inserting some data using
auto id generation. so in future i' don't know what the id it created.
now if i have
to insert some field in that doc, i have to search for previous fields and
update that doc.
i can do it using two queries search and if not exists then
update.
BUT my question is --> is there any way i can do it in one
query??????

thanks,
subhankar

--
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 elasticsearc...@**googlegroups.com.

For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

:frowning:

thanks,
subhankar

On Wednesday, 8 May 2013 18:51:40 UTC+5:30, Vineeth Mohan wrote:

This plugin is to update all existing documents by query. So if the
document does not exist , it wont do anything.
I believe what you need is "UPDATE IF EXISTS" , "CREATE IF NOT EXISTS"
AFAIK this cant be done in a single query (And hence not atomic)

Thanks
Vineeth

On Wed, May 8, 2013 at 6:24 PM, subhankar <neo20...@gmail.com<javascript:>

wrote:

hi vineeth,
i m very new to ES. i saw that earlier.
plz correct me if i am wrong. i think that is for index request. for
update api how this will work. i have to combine the query and update api
both.
and i think
https://github.com/yakaz/elasticsearch-action-updatebyquery will satisfy
the requirement. what do you think. can you please give me a small example
??

Thanks,
subhankar

On Wednesday, 8 May 2013 18:05:13 UTC+5:30, Vineeth Mohan wrote:

Just see
Operation Type in http://www.elasticsearch.org/**
guide/reference/api/index_/http://www.elasticsearch.org/guide/reference/api/index_/

HTH

Thanks
Vineeth
On Wed, May 8, 2013 at 5:36 PM, subhankar neo20...@gmail.com wrote:

hi,
my use case is something like this: i m inserting some data using
auto id generation. so in future i' don't know what the id it created.
now if i have
to insert some field in that doc, i have to search for previous fields and
update that doc.
i can do it using two queries search and if not exists then
update.
BUT my question is --> is there any way i can do it in one
query??????

thanks,
subhankar

--
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 elasticsearc...@**googlegroups.com.

For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--
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 elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi ,

My apologies , there is one feature that you can use here , i missed it
earlier. Its caled upsert.
LINK - http://www.elasticsearch.org/guide/reference/api/update/

  • Generate the docID based on the content of your feed.
  • Use upsert to index the document. UPSERT is like update the document
    or create it.

Thanks

        Vineeth

On Wed, May 8, 2013 at 7:01 PM, subhankar neo20iitkgp@gmail.com wrote:

:frowning:

thanks,
subhankar

On Wednesday, 8 May 2013 18:51:40 UTC+5:30, Vineeth Mohan wrote:

This plugin is to update all existing documents by query. So if the
document does not exist , it wont do anything.
I believe what you need is "UPDATE IF EXISTS" , "CREATE IF NOT EXISTS"
AFAIK this cant be done in a single query (And hence not atomic)

Thanks
Vineeth

On Wed, May 8, 2013 at 6:24 PM, subhankar neo20...@gmail.com wrote:

hi vineeth,
i m very new to ES. i saw that earlier.
plz correct me if i am wrong. i think that is for index request. for
update api how this will work. i have to combine the query and update api
both.
and i think https://github.com/yakaz/elasticsearch-action-
updatebyqueryhttps://github.com/yakaz/elasticsearch-action-updatebyquery will
satisfy the requirement. what do you think. can you please give me a small
example ??

Thanks,
subhankar

On Wednesday, 8 May 2013 18:05:13 UTC+5:30, Vineeth Mohan wrote:

Just see
Operation Type in http://www.elasticsearch.org/g
uide/reference/api/index_/http://www.elasticsearch.org/guide/reference/api/index_/

HTH

Thanks
Vineeth
On Wed, May 8, 2013 at 5:36 PM, subhankar neo20...@gmail.com wrote:

hi,
my use case is something like this: i m inserting some data using
auto id generation. so in future i' don't know what the id it created.
now if i have
to insert some field in that doc, i have to search for previous fields and
update that doc.
i can do it using two queries search and if not exists then
update.
BUT my question is --> is there any way i can do it in one
query??????

thanks,
subhankar

--
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 elasticsearc...@**googlegroups.**com.

For more options, visit https://groups.google.com/groups/opt_outhttps://groups.google.com/groups/opt_out
.

--
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 elasticsearc...@**googlegroups.com.
For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out
.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

hi vineeth,
thats may a solution but UPSERT always takes the doc id to
process. and i m using ES auto generated id so i don't know the id in
advance . ihave to any way query ES to get the uuid. so may be it is not
possible. or else i have to use something like snowflake to produce the
unique id and process it.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Why don't you just create an id for each document that way you don't
need to deal with this. This can be something as simple as
concatenating and hashing the field values so instead of doing a
search for the known fields, just generate that hash and you know the
exact document id. Now adding a new field will change that hash so
you will need to delete the old doc and reindex with the new id. Not
specifying an id is bad practice unless you never need to update/get
that document again.

On Wed, May 8, 2013 at 10:52 AM, subhankar neo20iitkgp@gmail.com wrote:

hi vineeth,
thats may a solution but UPSERT always takes the doc id to
process. and i m using ES auto generated id so i don't know the id in
advance . ihave to any way query ES to get the uuid. so may be it is not
possible. or else i have to use something like snowflake to produce the
unique id and process it.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

+1 : definitely the way to go!

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 8 mai 2013 à 20:10, Matt Weber matt.weber@gmail.com a écrit :

Why don't you just create an id for each document that way you don't
need to deal with this. This can be something as simple as
concatenating and hashing the field values so instead of doing a
search for the known fields, just generate that hash and you know the
exact document id. Now adding a new field will change that hash so
you will need to delete the old doc and reindex with the new id. Not
specifying an id is bad practice unless you never need to update/get
that document again.

On Wed, May 8, 2013 at 10:52 AM, subhankar neo20iitkgp@gmail.com wrote:

hi vineeth,
thats may a solution but UPSERT always takes the doc id to
process. and i m using ES auto generated id so i don't know the id in
advance . ihave to any way query ES to get the uuid. so may be it is not
possible. or else i have to use something like snowflake to produce the
unique id and process it.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

hi maat,
thanks for ur reply. in my use case i'll have to frequently get
that id back to use else where. then i have produce the ids by myself.

thanks,
subhankar

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

What is the big overhead in creating the ID yourself. Just find the
hashcode or sum of content of your feed which is going to be unique for the
next dupe.

Thanks
Vineeth

On Thu, May 9, 2013 at 3:27 AM, subhankar neo20iitkgp@gmail.com wrote:

hi maat,
thanks for ur reply. in my use case i'll have to frequently get
that id back to use else where. then i have produce the ids by myself.

thanks,
subhankar

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

thanks for ur reply and advice. i'll create the id by myself.
basically i badly need a UUID generator. java native UUID generator does
not guarantee of uniqueness in distributed scenario (as per my superior).
is the ticketing server explained here(
http://blogs.perl.org/users/clinton_gormley/2011/10/elasticsearchsequence---a-blazing-fast-ticket-server.html
) is a good idea??

thanks,
subhankar

On Thursday, 9 May 2013 08:49:26 UTC+5:30, Vineeth Mohan wrote:

What is the big overhead in creating the ID yourself. Just find the
hashcode or sum of content of your feed which is going to be unique for the
next dupe.

Thanks
Vineeth

On Thu, May 9, 2013 at 3:27 AM, subhankar <neo20...@gmail.com<javascript:>

wrote:

hi maat,
thanks for ur reply. in my use case i'll have to frequently get
that id back to use else where. then i have produce the ids by myself.

thanks,
subhankar

--
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 elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.