Highlight: Nested search highlights entire phrase instead of matched term

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

{
    "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:

{
	"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:

{		
	"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:

{
    "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.

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