0

I built a auto-completion search with Elasticsearch 5.4 with highlighting the matches.

This is my search query:

GET statements/_search
    {
      "_source": ["uid","textversions.content"],
      "highlight": {
        "fields": {
          "textversions.content": {}
        }
      },
      "query": {
        "match": {
          "textversions.content": {
            "query": "Informatik",
            "fuzziness": "AUTO"
          }
        }
      }
    }

Now, most of the results are highlighted correct. Here is an example:

  {
    "_index": "statements",
    "_type": "statement",
    "_id": "118",
    "_score": 15.151196,
    "_source": {
      "uid": 118,
      "textversions": [
        {
          "content": "die Nachfrage nach Informatikern auch groß ist"
        }
      ]
    },
    "highlight": {
      "textversions.content": [
        "die Nachfrage nach <em>Informatikern</em> auch groß ist"
      ]
    }
  }

But i have some results, where my textversions.content isn't completely in the highlighted version:

{
    "_index": "statements",
    "_type": "statement",
    "_id": "252",
    "_score": 15.809544,
    "_source": {
      "uid": 252,
      "textversions": [
        {
          "content": "es im Informatikstudium darum geht, sich mit Themen, die für einen Informatiker im späteren Leben absolut notwendig sind, auseinanderzusetzen und nicht mit anderen Fächern"
        }
      ]
    },
    "highlight": {
      "textversions.content": [
        "es im <em>Informatikstudium</em> darum geht, sich mit Themen, die für einen <em>Informatiker</em> im späteren Leben"
      ]
    }
  }

or is split into two separate sentences:

{
    "_index": "statements",
    "_type": "statement",
    "_id": "37",
    "_score": 12.162964,
    "_source": {
      "uid": 37,
      "textversions": [
        {
          "content": "die Abiturzeugnisse über die vorhandenen Informatikkenntnisse sehr wenig aussagen, schließlich haben nur relativ wenige Schulen überhaupt Informatik als ernstzunehmendes Fach"
        }
      ]
    },
    "highlight": {
      "textversions.content": [
        "die Abiturzeugnisse über die vorhandenen <em>Informatikkenntnisse</em> sehr wenig aussagen, schließlich",
        " haben nur relativ wenige Schulen überhaupt <em>Informatik</em> als ernstzunehmendes Fach"
      ]
    }
  }

Does anyone know the solution for this misbehavior?

Thanks for your help.

Freddy
  • 156
  • 1
  • 8

1 Answers1

1

I found the answer in the docs: i had to add "number_of_fragments: 0", so highlighting won't break my text into fragments and returns the complete content.

Freddy
  • 156
  • 1
  • 8