# Highlighting without HTML tags but structured data

**URL:** <https://discuss.elastic.co/t/highlighting-without-html-tags-but-structured-data/164883>\
**Category:** Elasticsearch\
**Created:** [January 19, 2019, 7:23am UTC](https://discuss.elastic.co/t/highlighting-without-html-tags-but-structured-data/164883 "2019-01-19T07:23:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevemao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stevemao/32/39958_2.png) [@stevemao](https://discuss.elastic.co/u/stevemao)\
**Post date:** [January 19, 2019, 7:23am UTC](https://discuss.elastic.co/t/highlighting-without-html-tags-but-structured-data/164883/1 "2019-01-19T07:23:16Z")

</div>

In the docs, if I do

```auto
GET twitter/_search
{
    "query" : {
        "match_phrase": { "message": "number 1" }
    },
    "highlight" : {
        "fields" : {
            "message" : {
                "type": "plain",
                "fragment_size" : 15,
                "number_of_fragments" : 3,
                "fragmenter": "simple"
            }
        }
    }
}

```

A normal response is something like this (slightly modified message to be an array)

```auto
{
    ...
    "hits": {
        "total": 1,
        "max_score": 1.601195,
        "hits": [
            {
                "_index": "twitter",
                "_type": "_doc",
                "_id": "1",
                "_score": 1.601195,
                "_source": {
                    "user": "test",
                    "message": ["some message with the number 1"],
                    "date": "2009-11-15T14:12:12",
                    "likes": 1
                },
                "highlight": {
                    "message": [
                        " with the <em>number</em>",
                        " <em>1</em>"
                    ]
                }
            }
        ]
    }
}

```

How do I get highlight with structured data? EG:

```auto
{
    ...
    "hits": {
        "total": 1,
        "max_score": 1.601195,
        "hits": [
            {
                "_index": "twitter",
                "_type": "_doc",
                "_id": "1",
                "_score": 1.601195,
                "_source": {
                    "user": "test",
                    "message": ["some message with the number 1"],
                    "date": "2009-11-15T14:12:12",
                    "likes": 1
                },
                "highlight": {
                    "message": [{
                      "type": 'plain',
                      "content": "some message with the ",
                      "for" : "0"
                    }, {
                      "type": 'highlight',
                      "content": "number",
                      "for" : "0",
                      "style": "hlt1",
                      // "query" might be highlighted with similar data structure
                   }, {
                      "type": 'highlight',
                      "content": "1",
                      "for" : "0",
                      "style": "hlt2"
                   } ]
                }
            }
        ]
    }
}

```

`for` is to reference which element in the `message` array. The point of it is to reference the part in the source.

---

<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:** [February 16, 2019, 7:23am UTC](https://discuss.elastic.co/t/highlighting-without-html-tags-but-structured-data/164883/2 "2019-02-16T07:23:16Z")

</div>

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