# Highlight: Nested search highlights entire phrase instead of matched term

**URL:** https://discuss.elastic.co/t/highlight-nested-search-highlights-entire-phrase-instead-of-matched-term/323934
**Category:** Elasticsearch
**Created:** [January 25, 2023, 2:49pm UTC](https://discuss.elastic.co/t/highlight-nested-search-highlights-entire-phrase-instead-of-matched-term/323934 "2023-01-25T14:49:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sandy01](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandy01/32/116387_2.png) [@sandy01](https://discuss.elastic.co/u/sandy01)
#### Post date: [January 25, 2023, 2:49pm UTC](https://discuss.elastic.co/t/highlight-nested-search-highlights-entire-phrase-instead-of-matched-term/323934/1 "2023-01-25T14:49:30Z")

</div>

Hello,  
I have a lot of data of this type:

```auto
{
    "timestamp": "2021-01-01T01:22:31"
    "urls": [
        {
            "visited": false,
            "url": "https://drive.google.com",
        },
        {
            "visited": true,
            "url": "https://www.google.com",
        },   
        {
            "visited": true,
            "url": "https://discuss.elastic.co/"
        }                        
    ]
},
{
    "timestamp": "2021-05-13T06:32:11"
    "urls": [
        {
            "visited": false,
            "url": "https://maps.google.com",
        },
        {
            "visited": true,
            "url": "https://google.com/"
        }                        
    ]
},
...

```

and this is my **mapping** :

```auto
{
	"settings": {
		"analysis": {
			"analyzer": {
				"my_analyzer": {
					"tokenizer": "standard",
					"filter": [
						"lowercase",
					]
				}
			}
		}
	},
	"mappings": {
		"properties": {					
			"timestamp": { 
				"type": "date" 
			},
			"urls": {
				"type": "nested",
				"properties": {
					"url": {
						"type": "text",
						"analyzer": "my_analyzer",
						"term_vector": "with_positions_offsets",
					},
					"visited": {
						"type": "boolean"
					}
				}
			}			
		}
	}
}

```

This is my query:

```auto
{		
	"query": {
	    "nested": {
	      	"path": "urls",
	      	"query": {
				"bool": {
					"must": [
						{					
					        "query_string":{
						        "query": "urls.url:*elastic.co",
					      	}
					    },
						# {
						# "range": {
						# "timestamp": {
						# "gt": "2021-03-01T00:00:00"
						# }
						# }
						# },						    
				    ]
				}
			},
	        "inner_hits": {
	        	"size":100,
	        	"highlight": {
					"fields": {
						"urls.url": {
							"type": "fvh",
							"number_of_fragments": 0
						},
					},
				}	
	      	}
	    }
	},
}

```

And this is my **output** :

```auto
{
    "urls": {
        "hits": {
            "total": {
                "value": 1,
                "relation": "eq"
            },
            "max_score": 1.0,
            "hits": [
                {
                    "_index": "my_index",
                    "_id": "aabbccddeeff",
                    "_nested": {
                        "field": "urls",
                        "offset": 8
                    },
                    "_score": 1.0,
                    "_source": {
                        "visited": true,
                        "url": "https://discuss.elastic.co"
                    },
                    "highlight": {
                        "urls.url": [
                            "https://<em>discuss.elastic.co</em>"
                        ]
                    }
                }
            ]
        }
    }
}

```

So, I have 2 issues:

- I wish to have highlight on `<em>elastic.co</em>` (since it was the original keyword) instead of `<em>discuss.elastic.co</em>`
- if I remove `range` comments from query, I have no results.

---

<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: [February 22, 2023, 2:50pm UTC](https://discuss.elastic.co/t/highlight-nested-search-highlights-entire-phrase-instead-of-matched-term/323934/2 "2023-02-22T14:50:16Z")

</div>

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