We are using a search query:
[
{
$search: {
index: "datasets",
compound: {
must: [
{
text: {
query: "subscription",
path: "name",
fuzzy: {
maxEdits: 1,
prefixLength: 3,
},
},
},
],
should: [
{
wildcard: {
path: "tags",
query: "*",
allowAnalyzedField: true,
score: {
constant: { value: 100 },
},
},
},
],
},
highlight: {
path: ["name"],
},
},
},
{
$addFields: {
highlight: {
$meta: "searchHighlights",
},
},
},
]
This query finds subscription
in entity name, and also boosts the score if the entity has any tag. Both name
and tags
are string
fields. The highlight should return matches in name
.
However, for name cs_subscription_v2
the highlight response is
- value: "cs", type: "hit"
- value: "_", type: "text"
- value: "subscription", type: "hit"
- value: "_", type: "text"
- value: "v2", type: "hit"
There are 3 hits, while it should only be 1.
We also notice that if we remove the should
section using wildcard match in the query, then the highlight works correctly.
Anyone knows why this happens, and how to walk around it? Is this a bug? Thanks!