# \[Highlighting\] Performance & Simplicity

**URL:** <https://discuss.elastic.co/t/highlighting-performance-simplicity/99751>\
**Category:** Elasticsearch\
**Created:** [September 7, 2017, 5:46pm UTC](https://discuss.elastic.co/t/highlighting-performance-simplicity/99751 "2017-09-07T17:46:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmaqsood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mmaqsood/32/22213_2.png) [@mmaqsood](https://discuss.elastic.co/u/mmaqsood)\
**Post date:** [September 7, 2017, 5:46pm UTC](https://discuss.elastic.co/t/highlighting-performance-simplicity/99751/1 "2017-09-07T17:46:15Z")

</div>

I have a scenario where I am forced to use a strict query filter, to filter my results, without a query block, and therefore cannot use highlighting without a highlight\_query as there is no query block in my main query.

My query is as follows:  
{  
query: {  
filtered {  
filter: {  
bool: {  
must: {  
multi\_match: {  
query: 'Samantha',  
fields: ['firstName', 'middleName', 'lastName']  
}  
}  
}  
}  
}  
}  
}

I've experienced that straightforward highlighting won't work, as there is no query block; only a filter block, so highlighting doesn't know what to highlight. I assume the following should not work:

```
	highlight: {
		fields: {
			firstName: {},
			middleName: {},
			lastName: {}
		}
	}

```

What I did instead is use the highlight\_query. My only concerns with this is repeating the same query for each field, which seems redundant and unneccesary to do. This might blow up my query if I have a lot of fields. In addition, my concern with performance is that it will be running the same query for each field. This is what I have:

```
highlight: {
	fields: {
		firstName: {
			highlight_query: {
				bool: {
					must: {
						match: {
							firstName: 'Samantha'
						}
					}
				}
			}
		},
		middleName: {
			highlight_query: {
				bool: {
					must: {
						match: {
							middleName: 'Samantha'
						}
					}
				}
			}
		},
		lastName: {
			highlight_query: {
				bool: {
					must: {
						match: {
							lastName: 'Samantha'
						}
					}
				}
			}
		}
	}
}

```

Could anyone answer the following questions?

1. Is there a more generic way of saying that this is my query and these are my fields, other than repeating the query for each field?
2. Is there a performance concern by repeating the queries for each field, will the same query be ran for each field? Is this normal behaviour even in a "multi-match"?
3. Is there a concern with my request being too big if I have 100 fields, and 100 query blocks for each field?

Thanks.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [September 15, 2017, 9:43am UTC](https://discuss.elastic.co/t/highlighting-performance-simplicity/99751/2 "2017-09-15T09:43:29Z")

</div>

Generally, filters are structured choices that people make e.g. date or price ranges, brand names.

- They don't normally expect highlighting and they are common to many searches (e.g. many user wanting to share the same cached date filter for "today").
- They don't use scoring to make one match better than another

Things that get highlighted are normally free-text unstructured searches expressed as _queries_ because they aren't filters common to many users and they require scoring for relevance ranking e.g. multi-match with cross\_fields mode will help score a match on firstName:Samantha higher than lastName:Samantha

So the question is perhaps why is "Samantha" a filter not a query in the first place?

---

<div class="post-metadata">

**Author:** ![mmaqsood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mmaqsood/32/22213_2.png) [@mmaqsood](https://discuss.elastic.co/u/mmaqsood)\
**Post date:** [September 18, 2017, 1:37pm UTC](https://discuss.elastic.co/t/highlighting-performance-simplicity/99751/3 "2017-09-18T13:37:06Z")

</div>

That makes sense. I believe it's a filter because we've been following this structure in our app for a long time that we probably need to change. Long story short, highlighting is not meant for filters, and using a highlight query to do so will probably result in unexpected and undesired behaviour.

---

<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:** [October 16, 2017, 1:37pm UTC](https://discuss.elastic.co/t/highlighting-performance-simplicity/99751/4 "2017-10-16T13:37:26Z")

</div>

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