-
Notifications
You must be signed in to change notification settings - Fork 727
Define the _id field as id for an object #7
Comments
Hi Alex, Sorry for late response, did you check @JestId annotation? Does it fit for you case? I think, we are not clearly understand the exact problem. Can you please gist your modifications? Ferhat |
Hi Ferhat, Thank you for you answer. My ticket is not clear, sorry for that :s Let's say that I've this document into my scala code : case class Test (
@JestId
id: Int = 1,
content: String = "lopsum",
author: String = "Me"
) If I well understood the usage of @JestId when I use {
"id" : 1,
"content" : "lopsum",
"author" : "Me"
} and if I want to get it with {
"_index" : "jobzazjswwmi7cqb",
"_type" : "document",
"_id" : "1",
"_version" : 2,
"exists" : true, "_source" : {"id" : 1, "content": "lopsum", "author": "Me"}
} What I want to do is that I want to insert into elasticsearch without to specify the id of my document to let elasticsearch manage the auto-increment. So I have the same {
"content" : "lopsum",
"author" : "Me"
} and my own parser to make the binding with my class as follow :
Without this, if I want to use the index method from Jest, I have to get the lastest Id from my index/type (eg: 1 in my example) then set this value + 1 into my Test.id then index it with Jest. Here a link to show want I'm looking for and a possible solution : |
Hi Alex, Thanks for information. I have some improvements and now results are; Mark your id field with JestId but set it to null (or just be sure it is null global variables etc.). case class Test (
@JestId
id: String = null,
content: String = "lopsum",
author: String = "Me"
) If you index this Test object Test source = new Test();
Index index = new Index.Builder(source).index("app").type("document").build(); Id of this document will automatically created by ES. Now if we search from ES; Search search = new Search(query)
JestResult result = client.execute(search);
List<Test> articleResult = result.getSourceAsObjectList(Test.class); List of Test objects' id values will be auto generated values. Does it cover your case ? Ferhat |
Ferhat, That's exactly what I was looking for ! Thank you ! |
Excellent! You are welcome. We are getting close to release 0.0.2. |
Actually, I have to implement my own json parser to handle the elasticsearch json because I want to use the _id as value for my object's variable id. For me, it's the easy way to have an auto-increment id from elasticsearch that I can use as identifier for my doc.
The other way is :
Here a good example to do so by using the _version as auto-increment : http://blogs.perl.org/users/clinton_gormley/2011/10/elasticsearchsequence---a-blazing-fast-ticket-server.html
The text was updated successfully, but these errors were encountered: