# Field\_masking\_span - Not working as expected with span queries

**URL:** <https://discuss.elastic.co/t/field-masking-span-not-working-as-expected-with-span-queries/268704>\
**Category:** Elasticsearch\
**Created:** [March 29, 2021, 8:55pm UTC](https://discuss.elastic.co/t/field-masking-span-not-working-as-expected-with-span-queries/268704 "2021-03-29T20:55:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)\
**Post date:** [March 29, 2021, 8:55pm UTC](https://discuss.elastic.co/t/field-masking-span-not-working-as-expected-with-span-queries/268704/1 "2021-03-29T20:55:11Z")

</div>

Hi,

I am using `field_masking_span` to find spans across two different fields, a stemmed field (`text`) and an unstemmed field (`text.unstemed`).

In particular, I am trying to search for the word `loss` in the `text` field, and then trying to find `economic` and `loss` in `text.unstemmed` fields. Analyzing the word `loss` is also `loss`, so the first part of the query _should_ not narrow anything, but it does.

Can the `field_masking_span` be used in the way I am using it below? Am I doing something incorrect here?

Below is the command that is **NOT** working. It returns no results against my search index.

```auto
    curl -s $ES_USER -XPOST $BASE/$INDEX/_search?pretty -H "Content-Type: application/json" -d '{
      "docvalue_fields": [
        "docket_exact",
        "date_filed"
      ],
      "from": 0,
      "query": {
        "bool": {
          "filter": [
            {
              "span_near": {
                "in_order": false,
                "slop": 9,
                "clauses": [{
                    "span_term": {
                      "text": "loss"
                    }
                  },{
                    "field_masking_span": {
                      "query": {
                        "span_near": {
                          "in_order": true,
                          "clauses": [{
    						  "span_term": {
    						    "text.unstemmed": "economic"
    						  }
    						},{
                              "span_term": {
                                "text.unstemmed": "loss"
                              }
                            }
                          ],
                          "slop": 0
                        }
                      },
                      "field": "text"
                    }
                  }
                ]
              }
            },
            {
              "range": {
                "date_filed": {
                  "gte": "2021-04-01T00:00:00"
                }
              }
            }
          ]
        }
      },
      "size": 1
    }'

```

However, if I remove the first `loss` clause in the outer span, then the query works. Note that this _should_ make no difference because `loss` is also in the `text.unstemed` field.

```auto
    curl -s $ES_USER -XPOST $BASE/$INDEX/_search?pretty -H "Content-Type: application/json" -d '{
      "docvalue_fields": [
        "documenttitle_exact",
        "docket_exact",
        "court_exact",
        "date_filed"
      ],
      "from": 0,
      "query": {
        "bool": {
          "filter": [
            {
              "span_near": {
                "in_order": false,
                "clauses": [
                  {
                    "field_masking_span": {
                      "query": {
                        "span_near": {
                          "in_order": true,
                          "clauses": [
    						{
    						  "span_term": {
    						    "text.unstemmed": "economic"
    						  }
    						},
                            {
                              "span_term": {
                                "text.unstemmed": "loss"
                              }
                            }
                          ],
                          "slop": 0
                        }
                      },
                      "field": "text"
                    }
                  }
                ],
                "slop": 9
              }
            },
            {
              "range": {
                "date_filed": {
                  "gte": "2021-04-01T00:00:00"
                }
              }
            }
          ]
        }
      },
      "size": 1
    }' 2>/dev/null

```

---

<div class="post-metadata">

**Author:** ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)\
**Post date:** [March 29, 2021, 10:30pm UTC](https://discuss.elastic.co/t/field-masking-span-not-working-as-expected-with-span-queries/268704/2 "2021-03-29T22:30:53Z")

</div>

I think I identified the issue. While indexing, I was indexing multiple values in the same field, which may have messed up term vectors. If anyone runs into this again, please be sure to double check how you indexed your content, and specifically for multi-value fields.

---

<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:** [April 26, 2021, 10:31pm UTC](https://discuss.elastic.co/t/field-masking-span-not-working-as-expected-with-span-queries/268704/3 "2021-04-26T22:31:52Z")

</div>

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