Repository: elastic-rs/elastic (language: rust)

Issue:
Get the document id in Hit
When I do a search I obtain  set of Hits. Each hit have the _source, however none of them have the _id automatically assigned by Elasticsearch.
I know that tipically you put your own id and a field indicating it, but this is not even recommended.

To have a good performance you have to let Elasticsearch create an id for the document. I have been working with elasticsearch since 2.1 version and it was always like that.

So my question is, how can I obtain the document id from a hit? I need it because I want to do some work with the documents and update or delete them.


Discussion / hints:
Hi @2phost :wave:

It looks like we're just missing the `id` field on our hits response type. I'll fix this up.

Fix patch:
diff --git a/src/responses/src/search.rs b/src/responses/src/search.rs
index bbfb89eb1e..5c4cc905f8 100644
--- a/src/responses/src/search.rs
+++ b/src/responses/src/search.rs
@@ -239,6 +239,8 @@ pub struct Hit<T> {
     index: String,
     #[serde(rename = "_type")]
     ty: String,
+    #[serde(rename = "_id")]
+    id: String,
     #[serde(rename = "_version")]
     version: Option<u32>,
     #[serde(rename = "_score")]
@@ -270,6 +272,11 @@ impl<T> Hit<T> {
         &self.ty
     }
 
+    /** The id of the hit. */
+    pub fn id(&self) -> &str {
+        &self.id
+    }
+
     /** The version of the hit. */
     pub fn version(&self) -> Option<u32> {
         self.version.clone()


Test patch: