# Wildcard matches are not highlighted in complex query containing field\_masking\_span

**URL:** <https://discuss.elastic.co/t/wildcard-matches-are-not-highlighted-in-complex-query-containing-field-masking-span/325301>\
**Category:** Elasticsearch\
**Created:** [February 10, 2023, 9:42pm UTC](https://discuss.elastic.co/t/wildcard-matches-are-not-highlighted-in-complex-query-containing-field-masking-span/325301 "2023-02-10T21:42:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![claudinoac](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/claudinoac/32/117130_2.png) [@claudinoac](https://discuss.elastic.co/u/claudinoac)\
**Post date:** [February 10, 2023, 9:42pm UTC](https://discuss.elastic.co/t/wildcard-matches-are-not-highlighted-in-complex-query-containing-field-masking-span/325301/1 "2023-02-10T21:42:05Z")

</div>

I'm applying the unified highlighter to the query below and the matched terms are being correctly highlighted, except by the ones matched by the wildcard term.  
That happens only when there is a `field_masking_span` term in the query.

Here's the query:

```auto
{
  "highlight": {
    "fields": {
      "*": {
        "require_field_match": true,
        "force_source": true,
        "fragment_size": 100000,
        "pre_tags": "<res>",
        "post_tags": "</res>"
      }
    }
  },
  "query": {
    "span_near": {
      "clauses": [
        {
          "span_near": {
            "clauses": [
              {
                "span_term": {
                  "result": "election"
                }
              },
              {
                "span_near": {
                  "clauses": [
                    {
                      "span_multi": {
                        "match": {
                          "wildcard": {
                            "result": {
                              "value": "presid*"
                            }
                          }
                        }
                      }
                    },
                    {
                      "span_term": {
                        "result": "protest"
                      }
                    }
                  ],
                  "slop": 4,
                  "in_order": false
                }
              }
            ],
            "slop": 2147483647,
            "in_order": false
          }
        },
        {
          "field_masking_span": {
            "query": {
              "span_term": {
                "loaded": "yes"
              }
            },
            "field": "result"
          }
        }
      ],
      "slop": 2147483647,
      "in_order": false
    }
  }
}

```

The following query returns all the hightlighted results, including the wildcard matches:

```auto
{
  "highlight": {
    "fields": {
      "*": {
        "require_field_match": true,
        "force_source": true,
        "fragment_size": 100000,
        "pre_tags": "<res>",
        "post_tags": "</res>"
      }
    }
  },
  "query": {
    "span_near": {
      "clauses": [
        {
          "span_term": {
            "result": "election"
          }
        },
        {
          "span_near": {
            "clauses": [
              {
                "span_multi": {
                  "match": {
                    "wildcard": {
                      "result": {
                        "value": "presid*"
                      }
                    }
                  }
                }
              },
              {
                "span_term": {
                  "result": "protest"
                }
              }
            ],
            "slop": 4,
            "in_order": false
          }
        }
      ],
      "slop": 2147483647,
      "in_order": false
    }
  }
}

```

Am I missing something here?

---

<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:** [March 10, 2023, 9:42pm UTC](https://discuss.elastic.co/t/wildcard-matches-are-not-highlighted-in-complex-query-containing-field-masking-span/325301/2 "2023-03-10T21:42:17Z")

</div>

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