elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
1.09k stars 24.83k forks source link

Unified Highlighter Requires Indexing Offsets error for Interval queries #105261

Open mayya-sharipova opened 9 months ago

mayya-sharipova commented 9 months ago

Elasticsearch Version

8.12

Problem Description

When using Unified Highlighter with interval queries where some words are skipped because of analyzer the following error is produced:

"reason": "field 'content' was indexed without offsets, cannot highlight"

even though the field was indexed with offsets.

Steps to Reproduce

PUT index1
{
  "mappings": {
    "properties": {
      "content": {
        "type": "text",
        "term_vector": "with_positions_offsets",
        "analyzer": "classic"
      }
    }
  }
}

POST index1/_bulk?refresh=true
{ "index" : {"_id": 1} }
{"content": "The quick brown fox jumps over the lazy dog"}

GET index1/_search
{
  "query": {
    "intervals": {
      "content": {
        "match": {
          "max_gaps": 2,
          "ordered": true,
          "query": "quick brown fox jumps over the lazy dog"
        }
      }
    }
  },
  "highlight": {
    "fields": {
      "content": {
        "type": "unified"
      }
    }
  }
}

Error stacktrace:

 "stack_trace": """java.lang.IllegalArgumentException: field 'content' was indexed without offsets, cannot highlight
    at org.apache.lucene.highlighter@9.9.1/org.apache.lucene.search.uhighlight.FieldHighlighter.highlightOffsetsEnums(FieldHighlighter.java:157)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.lucene.search.uhighlight.CustomFieldHighlighter.highlightOffsetsEnums(CustomFieldHighlighter.java:106)
    at org.apache.lucene.highlighter@9.9.1/org.apache.lucene.search.uhighlight.FieldHighlighter.highlightFieldForDoc(FieldHighlighter.java:83)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.lucene.search.uhighlight.CustomFieldHighlighter.highlightFieldForDoc(CustomFieldHighlighter.java:63)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.lucene.search.uhighlight.CustomUnifiedHighlighter.highlightField(CustomUnifiedHighlighter.java:148)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.search.fetch.subphase.highlight.DefaultHighlighter.highlight(DefaultHighlighter.java:80)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.search.fetch.subphase.highlight.HighlightPhase$1.process(HighlightPhase.java:69)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.search.fetch.FetchPhase$1.nextDoc(FetchPhase.java:163)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.search.fetch.FetchPhaseDocsIterator.iterate(FetchPhaseDocsIterator.java:70)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.search.fetch.FetchPhase.buildSearchHits(FetchPhase.java:169)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.search.fetch.FetchPhase.execute(FetchPhase.java:78)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:717)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:688)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.search.SearchService.lambda$executeQueryPhase$2(SearchService.java:545)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:73)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable$3.accept(ActionRunnable.java:70)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.action.ActionRunnable$4.doRun(ActionRunnable.java:95)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:33)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)
    at org.elasticsearch.server@8.12.0/org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1583)
elasticsearchmachine commented 9 months ago

Pinging @elastic/es-search (Team:Search)

mayya-sharipova commented 9 months ago

created a Lucene issue for this: https://github.com/apache/lucene/issues/13103

elasticsearchmachine commented 4 months ago

Pinging @elastic/es-search-relevance (Team:Search Relevance)