# No highlighting with intervals/fuzzy queries

**URL:** <https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259>\
**Category:** Elasticsearch\
**Created:** [April 22, 2020, 12:41pm UTC](https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259 "2020-04-22T12:41:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [April 22, 2020, 12:41pm UTC](https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259/1 "2020-04-22T12:41:40Z")

</div>

In a recent [feature request](https://discuss.elastic.co/t/fuzziness-support-in-intervals-query/208935), the `intervals` query was extended to support `fuzzy` rules.

I'm now trying to figure out why highlighting doesn't work with `intervals/fuzzy` whereas it does work with `intervals/match` and `span_near/fuzzy`.

Let's index a sample document:

```
POST test-index/_doc/1
{
  "text": "The quick brown fox jumps over the lazy dog"
}

```

Using the `span_near/fuzzy` query, it works:

```
POST test-index/_search
{
  "highlight": {
    "number_of_fragments": 1,
    "fragment_size": 100,
    "fields": {
      "text": {
        "type": "unified"
      }
    }
  },
  "query": {
    "span_near": {
      "clauses": [
        {
          "span_multi": {
            "match": {
              "fuzzy": {
                "text": {
                  "fuzziness": "AUTO",
                  "value": "quick"
                }
              }
            }
          }
        },
        {
          "span_multi": {
            "match": {
              "fuzzy": {
                "text": {
                  "fuzziness": "AUTO",
                  "value": "lazy"
                }
              }
            }
          }
        }
      ],
      "slop": 5,
      "in_order": false
    }
  }
}

```

Response:

```
"hits" : [
  {
    "_index" : "test-index",
    "_type" : "_doc",
    "_id" : "1",
    "_score" : 0.119415164,
    "_source" : {
      "text" : "The quick brown fox jumps over the lazy dog"
    },
    "highlight" : {
      "text" : [
        "The <em>quick</em> brown fox jumps over the <em>lazy</em> dog"
      ]
    }
  }
]

```

Using the `intervals/match` query, it also works:

```
POST test-index/_search
{
  "highlight": {
    "number_of_fragments": 1,
    "fragment_size": 100,
    "fields": {
      "text": {
        "type": "unified"
      }
    }
  },
  "query": {
    "intervals": {
      "text": {
        "all_of": {
          "ordered": false,
          "max_gaps": 5,
          "intervals": [
            {
              "match": {
                "query": "quick"
                
              }
            },
            {
              "match": {
                "query": "lazy"
              }
            }
          ]
        }
      }
    }
  }
}

```

Response:

```
"hits" : [
  {
    "_index" : "test-index",
    "_type" : "_doc",
    "_id" : "1",
    "_score" : 0.14285713,
    "_source" : {
      "text" : "The quick brown fox jumps over the lazy dog"
    },
    "highlight" : {
      "text" : [
        "The <em>quick</em> brown fox jumps over the <em>lazy</em> dog"
      ]
    }
  }
]

```

Finally, we the `intervals/fuzzy` query, it doesn't work (i.e. no `highlight` section in the response):

```
POST test-index/_search
{
  "highlight": {
    "number_of_fragments": 1,
    "fragment_size": 100,
    "fields": {
      "text": {
        "type": "unified"
      }
    }
  },
  "query": {
    "intervals": {
      "text": {
        "all_of": {
          "ordered": false,
          "max_gaps": 5,
          "intervals": [
            {
              "fuzzy": {
                "term": "quick"
              }
            },
            {
              "fuzzy": {
                "term": "lazy"
              }
            }
          ]
        }
      }
    }
  }
}

```

Response:

```
"hits" : [
  {
    "_index" : "test-index",
    "_type" : "_doc",
    "_id" : "1",
    "_score" : 0.14285713,
    "_source" : {
      "text" : "The quick brown fox jumps over the lazy dog"
    }
  }
]

```

Would anyone have any idea why? @jimczi maybe?  
Thank you so much!

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [April 22, 2020, 3:00pm UTC](https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259/2 "2020-04-22T15:00:54Z")

</div>

@romseygeek can you take a look ?

---

<div class="post-metadata">

**Author:** ![AlanWoodward](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alanwoodward/32/41962_2.png) [@AlanWoodward](https://discuss.elastic.co/u/AlanWoodward)\
**Post date:** [April 22, 2020, 3:19pm UTC](https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259/3 "2020-04-22T15:19:14Z")

</div>

Hi @val, can you tell me which version of ES you're using?

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [April 22, 2020, 8:05pm UTC](https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259/4 "2020-04-22T20:05:46Z")

</div>

Hi @AlanWoodward, thanks for dropping by.

Indeed, I forgot to mention the version. I'm using 7.6.1

---

<div class="post-metadata">

**Author:** ![AlanWoodward](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alanwoodward/32/41962_2.png) [@AlanWoodward](https://discuss.elastic.co/u/AlanWoodward)\
**Post date:** [April 23, 2020, 11:59am UTC](https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259/5 "2020-04-23T11:59:08Z")

</div>

This should be fixed in the upcoming 7.7 release; the issue is how the fuzzy intervals source is implementing its `visit()` method - in 7.6 we are using a version of lucene that doesn't properly support visiting fuzzy automata, but this has been fixed in lucene 8.5 (LUCENE-9212) which will be used in elasticsearch 7.7.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [April 23, 2020, 1:33pm UTC](https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259/6 "2020-04-23T13:33:41Z")

</div>

Fantastic, thanks for the insights @AlanWoodward !!  
Eager to test this in ES 7.7 soon.

---

<div class="post-metadata">

**Author:** ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)\
**Post date:** [May 19, 2020, 3:30am UTC](https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259/7 "2020-05-19T03:30:31Z")

</div>

I'm happy to share that ES 7.7.0 (with Lucene 8.5) took care of this issue.

---

<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:** [June 16, 2020, 3:40am UTC](https://discuss.elastic.co/t/no-highlighting-with-intervals-fuzzy-queries/229259/8 "2020-06-16T03:40:44Z")

</div>

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