# Highlights not generated for certain Fuzzy & Wildcard Phrase match queries using Span

**URL:** <https://discuss.elastic.co/t/highlights-not-generated-for-certain-fuzzy-wildcard-phrase-match-queries-using-span/287815>\
**Category:** Elasticsearch\
**Created:** [October 27, 2021, 3:45pm UTC](https://discuss.elastic.co/t/highlights-not-generated-for-certain-fuzzy-wildcard-phrase-match-queries-using-span/287815 "2021-10-27T15:45:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maurice](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maurice/32/96410_2.png) [@maurice](https://discuss.elastic.co/u/maurice)\
**Post date:** [October 27, 2021, 3:45pm UTC](https://discuss.elastic.co/t/highlights-not-generated-for-certain-fuzzy-wildcard-phrase-match-queries-using-span/287815/1 "2021-10-27T15:45:46Z")

</div>

Hey everybody, I'm running into an issue with highlights not being generated for certain phrase match queries using wildcards or fuzzy matching with spans.

Included below are steps for test replication from Kibana.

Elasticsearch version 7.9.3

**1. Create Index**

```auto
PUT /test-index-1
{
  "mappings": {
    "properties": {
      "transcription_en": {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 10000
          }
        }
      }
    }
  }
}

```

**2. Create Document**

```auto
PUT /test-index-1/_doc/1
{
  "transcription_en": "this is an example of a transcription string for fuzzy and wildcard phrase matching"
}

```

**3. Check Queries**

**VALID QUERIES** - these generate highlights as expected

**3a.** Basic phrase match query:

```auto
GET test-index-1/_search
{
  "highlight": {
    "fields": {
      "transcription_en": {}
    },
    "number_of_fragments": 0
  },
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {"match_phrase": {"transcription_en": "phrase matching"}}
            ]
          }
        }
      ]
    }
  }
}

```

**3a.** Response:

```auto
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.5753642,
    "hits" : [
      {
        "_index" : "test-index-1",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.5753642,
        "_source" : {
          "transcription_en" : "this is an example of a transcription string for fuzzy and wildcard phrase matching"
        },
        "highlight" : {
          "transcription_en" : [
            "this is an example of a transcription string for fuzzy and wildcard <em>phrase</em> <em>matching</em>"
          ]
        }
      }
    ]
  }
}

```

**3b.** Fuzzy phrase match query:

```auto
GET test-index-1/_search
{
  "highlight": {
    "fields": {
      "transcription_en": {}
    },
    "number_of_fragments": 0
  },
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "span_near": {
                  "clauses": [
                    {
                      "span_multi": {
                        "match": {
                          "fuzzy": {
                            "transcription_en": {
                              "fuzziness": "auto",
                              "value": "phrasw"
                            }
                          }
                        }
                      }
                    },
                    {
                      "span_multi": {
                        "match": {
                          "fuzzy": {
                            "transcription_en": {
                              "fuzziness": "auto",
                              "value": "matching"
                            }
                          }
                        }
                      }
                    }
                  ],
                  "in_order": true,
                  "slop": 0
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

**3b.** Response:

```auto
{
  "took" : 23,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.5753642,
    "hits" : [
      {
        "_index" : "test-index-1",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.5753642,
        "_source" : {
          "transcription_en" : "this is an example of a transcription string for fuzzy and wildcard phrase matching"
        },
        "highlight" : {
          "transcription_en" : [
            "this is an example of a transcription string for fuzzy and wildcard <em>phrase</em> <em>matching</em>"
          ]
        }
      }
    ]
  }
}

```

# ========================================

**INVALID QUERIES** - these do NOT generate highlights

**3c.** Wildcard phrase match query:

```auto
GET test-index-1/_search
{
  "highlight": {
    "fields": {
      "transcription_en": {}
    },
    "number_of_fragments": 0
  },
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "span_near": {
                  "clauses": [
                    {
                      "span_multi": {
                        "match": {
                          "wildcard": {"transcription_en": {"value": "phras?"}}
                        }
                      }
                    },
                    {
                      "span_multi": {
                        "match": {
                          "wildcard": {"transcription_en": {"value": "matching"}}
                        }
                      }
                    }
                  ],
                  "in_order": true,
                  "slop": 0
                }
              }
            ]
          }
        }
      ]
    }
  }
}

```

**3c.** Response:

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.5753642,
    "hits" : [
      {
        "_index" : "test-index-1",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.5753642,
        "_source" : {
          "transcription_en" : "this is an example of a transcription string for fuzzy and wildcard phrase matching"
        }
      }
    ]
  }
}

```

**3d.** Alternate fuzzy phrase match query:

```auto
GET test-index-1/_search
{
  "highlight": {
    "fields": {
      "transcription_en": {}
    },
    "number_of_fragments": 0
  },
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "span_near": {
                  "clauses": [
                    {
                      "span_multi": {
                        "match": {
                          "fuzzy": {
                            "transcription_en": {
                              "fuzziness": "auto",
                              "value": "this"
                            }
                          }
                        }
                      }
                    },
                    {
                      "span_multi": {
                        "match": {
                          "fuzzy": {
                            "transcription_en": {
                              "fuzziness": "auto",
                              "value": "is"
                            }
                          }
                        }
                      }
                    },
                    {
                      "span_multi": {
                        "match": {
                          "fuzzy": {
                            "transcription_en": {
                              "fuzziness": "auto",
                              "value": "an"
                            }
                          }
                        }
                      }
                    },
                    {
                      "span_multi": {
                        "match": {
                          "fuzzy": {
                            "transcription_en": {
                              "fuzziness": "auto",
                              "value": "examplw"
                            }
                          }
                        }
                      }
                    }
                  ],
                  "in_order": true,
                  "slop": 0
                }
              }
            ] 
          }
        }
      ]
    }
  }
}

```

**3d.** Response:

```auto
{
  "took" : 7,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.1507283,
    "hits" : [
      {
        "_index" : "test-index-1",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.1507283,
        "_source" : {
          "transcription_en" : "this is an example of a transcription string for fuzzy and wildcard phrase matching"
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

**Author:** ![maurice](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maurice/32/96410_2.png) [@maurice](https://discuss.elastic.co/u/maurice)\
**Post date:** [October 27, 2021, 5:46pm UTC](https://discuss.elastic.co/t/highlights-not-generated-for-certain-fuzzy-wildcard-phrase-match-queries-using-span/287815/2 "2021-10-27T17:46:39Z")

</div>

It seems that using the `plain` highlighter rather than the default `unified` highlighter may resolve this issue but I am concerned about the performance implications of searching the number of documents I have with this change.

---

<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:** [November 24, 2021, 5:46pm UTC](https://discuss.elastic.co/t/highlights-not-generated-for-certain-fuzzy-wildcard-phrase-match-queries-using-span/287815/3 "2021-11-24T17:46:41Z")

</div>

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