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?
- 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?
- 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"?
- Is there a concern with my request being too big if I have 100 fields, and 100 query blocks for each field?
Thanks.