Auto generated id

Hi everyone,

I went over the Java code examples, and I saw that whenver
IndexResponse is created, the id value is always code-generated, i.e.

      for (int j = 0; j < BATCH; j++) {
                counter++;

request.add(Requests.indexRequest("test").type("type1").id(Integer.toString(counter))
.source(source(Integer.toString(counter),
sValues[counter % sValues.length], lValues[counter %
lValues.length])));
}

However, I would like to use something other than incrementing
counter, because in my project I have to index new document within
listener event, so I want to avoid using global variables. Is there
any way to create new id on the fly using Java classes from ES
library?

Thanks,
Eugene.

Just provide whatever id you want, if you don't provide one, then one will be generated for you.
On Wednesday, March 9, 2011 at 10:19 AM, eugene wrote:

Hi everyone,

I went over the Java code examples, and I saw that whenver
IndexResponse is created, the id value is always code-generated, i.e.

for (int j = 0; j < BATCH; j++) {
counter++;

request.add(Requests.indexRequest("test").type("type1").id(Integer.toString(counter))
.source(source(Integer.toString(counter),
sValues[counter % sValues.length], lValues[counter %
lValues.length])));
}

However, I would like to use something other than incrementing
counter, because in my project I have to index new document within
listener event, so I want to avoid using global variables. Is there
any way to create new id on the fly using Java classes from ES
library?

Thanks,
Eugene.

Thanks Shay, that worked! From your experience, is it better to put
muliple documents under one index, or create more indices for each
document (which I doubt is a good idea because you may run out of
space), or different types per single index for each new json entry?

On Mar 9, 12:24 am, Shay Banon shay.ba...@elasticsearch.com wrote:

Just provide whatever id you want, if you don't provide one, then one will be generated for you.

On Wednesday, March 9, 2011 at 10:19 AM, eugene wrote:

Hi everyone,

I went over the Java code examples, and I saw that whenver
IndexResponse is created, the id value is always code-generated, i.e.

for (int j = 0; j < BATCH; j++) {
counter++;

request.add(Requests.indexRequest("test").type("type1").id(Integer.toString­(counter))
.source(source(Integer.toString(counter),
sValues[counter % sValues.length], lValues[counter %
lValues.length])));
}

However, I would like to use something other than incrementing
counter, because in my project I have to index new document within
listener event, so I want to avoid using global variables. Is there
any way to create new id on the fly using Java classes from ES
library?

Thanks,
Eugene.- Hide quoted text -

  • Show quoted text -