Annotated text highlighting not working for wildcard fields

Im indexing some text using the annotated text plugin eg

DELETE test1
PUT test
{
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
      "properties":{
        "text":{
          "type":"annotated_text"
        }
      }
  }
}
POST test/_doc/1
{
  "text":"he had a meeting with the [President of Mexico](Andrés+Obrador&Mexico) today"
}

When I perform a search with highlighting for a specific field all is good:

POST test/_search
{
    "query": {
        "term": {
            "text": "Andrés Obrador"
        }
    },
    "highlight": {
        "type": "annotated",
        "fields": {
            "text": {}
        }
    }
}
"hits": [
      {
        "_index": "test",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.30873197,
        "_source": {
          "text": "he had a meeting with the [President of Mexico](Andrés+Obrador&Mexico) today"
        },
        "highlight": {
          "text": [
            "he had a meeting with the [President of Mexico](_hit_term=Andr%C3%A9s+Obrador&Andr%C3%A9s+Obrador&Mexico) today"
          ]
        }
      }
    ]

However if I perform the same search with a wildcard field the highlighting vanishes:

POST test/_search
{
    "query": {
        "term": {
            "text": "Andrés Obrador"
        }
    },
    "highlight": {
        "type": "annotated",
        "fields": {
            "*": {}
        }
    }
}
 "hits": [
      {
        "_index": "test",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.30873197,
        "_source": {
          "text": "he had a meeting with the [President of Mexico](Andrés+Obrador&Mexico) today"
        }
      }
    ]

Hi Rob,
Looking at the docs I can see that it says:

Only text and keyword fields are highlighted when you use wildcards. If you use a custom mapper and want to highlight on a field anyway, you must explicitly specify that field name.

Being a non-core field type (for now) and not the text type this would explain why the annotated_text field type is overlooked. I'm afraid you'll have to explicitly list the field names to highlight in your request.

Thanks, Ill continue with specifying all available fields

1 Like

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