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

Issue:
Add highlight to `Hit`
It would be cool to expose [highlighting](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html) search results in `Hit`.

There are two options I see:
1. Using `serde_json::Value` (with the associated methods):
	```rust
	pub struct Hit<T> {
	    ...
	    highlight: Option<Value>,
	}
	```

	where the JSON looks like:
	```json
	{
	  "some_field": ["this is the <em>highlight</em> of some_field"],
	  "some_other_field": ["this is the <em>highlight</em> of some_other_field"]
	}
	```
1. something like `Aggs` where we transform it to "row" style:
	```rust
	pub struct Highlight {
	    field: String,
	    // Not sure what to name this...?
	    highlight: Vec<String>,
	}

	pub struct Hit<T> {
	    ...
	    highlight: Option<Vec<Highlight>>,
	}
	```

	So it would look something like (in JSON):
	```json
	[
	  {
	    "field": "some_field",
	    "highlight": ["this is the <em>highlight</em> of some_field"]
	  },
	  {
	    "field": "some_other_field",
	    "highlight": ["this is the <em>highlight</em> of some_other_field"]
	  }
	]
	```

	The issue with this option is that I am not 100% sure that Elasticsearch returns highlight results the same way depending on that params you pass in to the query...

If we go with option 1, I have a PR pretty much ready (and option 2 won't take me too much time).

Also, should we deviate from Elasticsearch and rename it to `highlights`?


Discussion / hints:

Fix patch:
diff --git a/src/responses/src/search.rs b/src/responses/src/search.rs
index b1b0f035bd..dbbd91036a 100644
--- a/src/responses/src/search.rs
+++ b/src/responses/src/search.rs
@@ -251,6 +251,7 @@ pub struct Hit<T> {
     source: Option<T>,
     #[serde(rename = "_routing")]
     routing: Option<String>,
+    highlight: Option<Value>,
 }
 
 impl<T> Hit<T> {
@@ -288,6 +289,26 @@ impl<T> Hit<T> {
     pub fn score(&self) -> Option<f32> {
         self.score.clone()
     }
+
+    /**
+    A reference to the [highlighted] snippets of the part(s) of the field(s)
+    matching the search query.
+
+    [highlighted]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html
+    */
+    pub fn highlight(&self) -> Option<&Value> {
+        self.highlight.as_ref()
+    }
+
+    /**
+    A clone of the [highlighted] snippets of the part(s) of the field(s)
+    matching the search query.
+
+    [highlighted]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html
+    */
+    pub fn into_highlight(&self) -> Option<Value> {
+        self.highlight.clone()
+    }
 }
 
 /** Type Struct to hold a generic `serde_json::Value` tree of the aggregation results. */


Test patch: