# Elastic search Highlight in nested and normal object

**URL:** <https://discuss.elastic.co/t/elastic-search-highlight-in-nested-and-normal-object/128805>\
**Category:** Elasticsearch\
**Created:** [April 20, 2018, 6:56am UTC](https://discuss.elastic.co/t/elastic-search-highlight-in-nested-and-normal-object/128805 "2018-04-20T06:56:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![surajdalvi](https://avatars.discourse-cdn.com/v4/letter/s/85f322/32.png) [@surajdalvi](https://discuss.elastic.co/u/surajdalvi)\
**Post date:** [April 20, 2018, 6:56am UTC](https://discuss.elastic.co/t/elastic-search-highlight-in-nested-and-normal-object/128805/1 "2018-04-20T06:56:56Z")

</div>

Hi

I have created index and documents in the Elasticsearch by using following calls:

> ```
> PUT test
> {
> "mappings": {
> "documents": {
> "properties": {
> "fulltext": {
> "type": "text"
> },
> "title": {
> "type": "text",
> "fields": {
> "raw": {
> "type": "keyword"
> }
> }
> },
> "fields": {
> "type": "nested",
> "properties": {
> "uid": {
> "type": "keyword"
> },
> "value": {
> "type": "text",
> "copy_to": "fulltext"
> }
> }
> }
> }
> }
> }
> }
> 
> PUT test/documents/1
> {
> "title": "hello world",
> "fields": [
> {
> "uid": "fname",
> "value": "My first name is john"
> },
> {
> "uid": "lname",
> "value": "My last name is test"
> }
> ]
> }
> 
> PUT test/documents/2
> {
> "title": "java demo",
> "fields": [
> {
> "uid": "fname",
> "value": "My first name is Ritesh"
> },
> {
> "uid": "lname",
> "value": "My last name is testing"
> }
> ]
> }
> 
> ```

Now I am using **highlight** query to highlight matching text.by using following way:

> ```
> POST test/_search
> {
> "query": {
> "simple_query_string": {
> "query": "john"
> }
> },
> "highlight" : {
> "fields" : {
> "*" : {}
> }
> }
> }
> 
> ```

Above request giving me following response:

> ```
> {
> "took": 3,
> "timed_out": false,
> "_shards": {
> "total": 5,
> "successful": 5,
> "skipped": 0,
> "failed": 0
> },
> "hits": {
> "total": 1,
> "max_score": 0.2876821,
> "hits": [
> {
> "_index": "test",
> "_type": "documents",
> "_id": "1",
> "_score": 0.2876821,
> "_source": {
> "title": "hello world",
> "fields": [
> {
> "uid": "fname",
> "value": "My first name is john"
> },
> {
> "uid": "lname",
> "value": "My last name is test"
> }
> ]
> },
> "highlight": {
> "fields.value": [
> "My first name is <em>john</em>"
> ]
> }
> }
> ]
> }
> }
> 
> ```

But my question is "Can we highlight fields.uid also (in this case **fname** ) ?" by using above query  
It helps me to understand search results belongs to which uid(fields.uid)  
is any solution for this please help me into this?

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [April 27, 2018, 9:59pm UTC](https://discuss.elastic.co/t/elastic-search-highlight-in-nested-and-normal-object/128805/2 "2018-04-27T21:59:33Z")

</div>

Highlighter by default highlights only terms matching the search query. In your case it will be only "john". It can't highlight "fname", if you are not search for "fname" if your query.

If you want the highlighter highlight terms different from your search query, you can use `highlight_query` option.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 25, 2018, 9:59pm UTC](https://discuss.elastic.co/t/elastic-search-highlight-in-nested-and-normal-object/128805/3 "2018-05-25T21:59:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
