Expected result with highlighter in analyzed data


(Raj Kumar Natarajan) #1

I have indexed my data using few analyzers. Everything is fine. When I try to search the data using particular keyword, the analyzed result brings me the proper data. But the applied highlighter brings me only the exact matches.
For example, I've the indexed data like " a cat stalking a bird " so when I try to search " talking ", I see the above data appear in the result but not in the highlighted field.

Settings

{
	"index": {
		"analysis": {
			"analyzer": {
				"summary_analyzer": {
					"type": "custom",
					"char_filter": "html_strip",
					"tokenizer": "standard",
					"filter": ["standard",
					"loweritem",
					"mynGram"],
					"stopwords": "_english_"
				},
				"my_ngram_analyzer": {
					"type": "custom",
					"tokenizer": "my_ngram_tokenizer",
					"filter": ["standard",
					"loweritem"],
					"stopwords": "_english_"
				},
				"snowball_analyzer": {
					"type": "snowball",
					"language": "English",
					"stopwords": "_english_"
				},
				"loweritem_analyzer": {
					"type": "custom",
					"tokenizer": "keyword",
					"filter": ["loweritem"]
				},
				"shingle_analyzer": {
					"type": "custom",
					"tokenizer": "standard",
					"filter": ["myShingle"]
				},
				"entityReverse": {
					"type": "custom",
					"tokenizer": "keyword",
					"filter": "reverse"
				}
			},
			"filter": {
				"mynGram": {
					"type": "nGram",
					"min_gram": 2,
					"max_gram": 50,
					"token_chars": ["letter",
					"digit",
					"symbol",
					"punctuation"]
				},
				"myShingle": {
					"type": "shingle",
					"min_shingle_size": 2,
					"max_shingle_size": 2
				}
			},
			"tokenizer": {
				"my_ngram_tokenizer": {
					"type": "nGram",
					"min_gram": "2",
					"max_gram": "50",
					"token_chars": ["letter",
					"digit",
					"symbol",
					"punctuation"]
				}
			}
		}
	}
}

Query

{
	"from": 0,
	"size": 15,
	"query": {
		"filtered": {
			"query": {
				"bool": {
					"must": {
						"nested": {
							"query": {
								"match": {
									"items.isDeleted": {
										"query": 0,
										"type": "boolean"
									}
								}
							},
							"path": "items"
						}
					},
					"should": [{
						"nested": {
							"query": {
								"multi_match": {
									"query": "talking",
									"fields": ["items.itemTitle.raw^5",
									"items.itemTitle.my_ngram_title^3.5",
									"items.itemTitle.snowball_title^4",
									"items.itemTitle.loweritem_title^4"],
									"type": "phrase"
								}
							},
							"path": "items"
						}
					},
					{
						"nested": {
							"query": {
								"multi_match": {
									"query": "talking",
									"fields": ["itemSummary.summary.raw^1.5",
									"itemSummary.summary.analyzed_summary^0.5",
									"itemSummary.summary.snowball_summary"],
									"type": "phrase"
								}
							},
							"path": "itemSummary"
						}
					},
					{
						"match": {
							"items.itemId": {
								"query": "talking",
								"type": "boolean"
							}
						}
					}],
					"minimum_should_match": "2"
				}
			},
			"filter": {
				"or": {
					"filters": [{
						"term": {
							"roles": 1
						}
					},
					{
						"term": {
							"users": 327
						}
					}]
				}
			}
		}
	},
	"fields": ["*",
	"_source"],
	"sort": [{
		"items.isNotDraft": {
			"order": "asc",
			"mode": "min"
		}
	},
	{
		"_score": {
			
		}
	}],
	"highlight": {
		"fields": {
			*: {
				
			}
		}
	}
}

(Raj Kumar Natarajan) #2

Search Result

{
	"took": 53,
	"timed_out": false,
	"_shards": {
		"total": 5,
		"successful": 5,
		"failed": 0
	},
	"hits": {
		"total": 45,
		"max_score": null,
		"hits": [{
			"_index": "item",
			"_type": "itemdetails",
			"_id": "2fa5cba7435a9de83e8c838c5d602ee0",
			"_score": 1.6257544,
			"_source": {
				"items": {
					"idItem": "2fa5cba7435a9de83e8c838c5d602ee0",
					"itemTitle": "Talk to manager"
				},
				"itemsummary": {
					"idItemsummary": 7072,
					"summary": "While <em>talking</em> with HR she stated that at the"
				},
				"roles": [1,
				2,
				3],
				"users": [111]
			},
			"highlight": {
				"itemsummary.summary": ["While <em>talking</em> with HR she stated that at the"]
			},
			"sort": [1,
			1.6257544]
		},
		{
			"_index": "item",
			"_type": "itemdetails",
			"_id": "2fa5cba7435a9de83e8c838c5d602ee0",
			"_score": 1.6257544,
			"_source": {
				"items": {
					"idItem": "2fa5cba7435a9de83e8c838c5d602ee0",
					"itemTitle": "Stalking"
				},
				"itemsummary": {
					"idItemsummary": 7072,
					"summary": "Nothing"
				},
				"roles": [1,
				2,
				3],
				"users": [111]
			},
			"sort": [1,
			1.6257544]
		}]
	}
}

(system) #3