# Highlight each span\_term with a different tag

**URL:** https://discuss.elastic.co/t/highlight-each-span-term-with-a-different-tag/204136
**Category:** Elasticsearch
**Created:** [October 17, 2019, 10:08pm UTC](https://discuss.elastic.co/t/highlight-each-span-term-with-a-different-tag/204136 "2019-10-17T22:08:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![anycolife](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@anycolife](https://discuss.elastic.co/u/anycolife)
#### Post date: [October 17, 2019, 10:08pm UTC](https://discuss.elastic.co/t/highlight-each-span-term-with-a-different-tag/204136/1 "2019-10-17T22:08:35Z")

</div>

Is it possible to highlight each span\_term with a different tag?

For example:

```auto
PUT /my_index/_doc/1
{
  "text": "my interesting book"
}

```

then:

```auto
GET /my_index/_search
{
  "query": {
    "span_near": {
      "clauses": [
        { "span_term": { "text": { "value": "my" } }},
        { "span_gap": { "text": 1 }},
        { "span_term": { "text": { "value": "book" }}}
      ],
      "slop": 0,
      "in_order": true
    }
  },
  "highlight": {
    "number_of_fragments": 0,
    "fields": {
      "text": {
        "highlight_query": {
          "span_near": {
            "clauses": [
              { "span_term": { "text": { "value": "my" }}},
              { "span_multi": { "match": { "wildcard": { "text": "*" }}}},
              { "span_term": { "text": { "value": "book" }}}
            ],
            "slop": 0,
            "in_order": true
          }
        }
      }
    }
  }
}

```

returns:

```auto
<em>my</em> <em>interesting</em> <em>book</em>

```

Desirable result:

```auto
<em>my</em> <strong>interesting</strong> <em>book</em>

```

---

<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: [November 14, 2019, 10:08pm UTC](https://discuss.elastic.co/t/highlight-each-span-term-with-a-different-tag/204136/2 "2019-11-14T22:08:36Z")

</div>

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