I use elastic search 7.10 and like to find documents by wildcard search on analyzed fields and highlight those in text. But this doesn't work.
The document could contain the following example: "The color of the car is black."
I expect a result in which car
and black
is marked.
I have the following mapping:
"text": {
"type": "text",
"store": true,
"term_vector": "with_positions_offsets",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 8000
},
"wc" :{
"type": "wildcard"
}
}
},
I use the following query:
{
"query": {
"bool": {
"should": [
{
"match": {"text": "car"}
},
{
"wildcard": { "text.wc": { "value": "bl*" } }
}
]
}
},
"fields": ["text", "text.wc"],
"highlight": {
"pre_tags": [
"<span class='marker'>"
],
"post_tags": [
"</span>"
],
"type": "fvh",
"fields": {
"*": {
"pre_tags": [
"<em>"
],
"post_tags": [
"</em>"
]
}
},
"require_field_match": true
}
}
The query resultsets only contains highlight for the text
- field, but not for the text.wc
field. I also tried an separate wildcard-field, which is not an subfield of text
but this also does not work. I also notice, that _source
- field set to enabled
is needed, even if all the fields are set to store otherwise I get an Unable to retrieve the requested [fields]
message.
Question: How can I get highlighted text for a wildcrad searchterm?