# Using Span First with fuzziness

**URL:** <https://discuss.elastic.co/t/using-span-first-with-fuzziness/169604>\
**Category:** Elasticsearch\
**Created:** [February 22, 2019, 4:02pm UTC](https://discuss.elastic.co/t/using-span-first-with-fuzziness/169604 "2019-02-22T16:02:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmyalmeida](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jimmyalmeida](https://discuss.elastic.co/u/jimmyalmeida)\
**Post date:** [February 22, 2019, 4:02pm UTC](https://discuss.elastic.co/t/using-span-first-with-fuzziness/169604/1 "2019-02-22T16:02:11Z")

</div>

Hello,

I am new to Elasticsearch and i need to use the term of the search to gain score if it is in the beginning of the document but i need to use fuzziness in that term too. I tried something like this but i couldnt because the span\_first doesnt support fuzziness .

```
    POST /produto/default/_search
    {
      "_source": [
        "nome",
        "descricao",
        "categoria.nome"
      ],
      "query": {
        "bool": {
          "must": {
            "multi_match": {
              "query": "acucar",
              "tie_breaker": "1.0",
              "fields": [
                "nome",
                "descricao",
                "categoria.nome"
              ],
              "fuzziness": "auto"
            }
          },
          "should": [
            {
              "span_first": {
                "match": {
                  "span_term": {
                    "nome": "acucar"
                  }
                },
                "end": 1
              }
            },
            {
              "span_first": {
                "match": {
                  "span_term": {
                    "nome": "acucar"
                  }
                },
                "end": 2,
                "fuzziness": "auto"
              }
            }
      ]
    }
  }
}

```

Is it possible to do it in another way?

Thanks in advance and sorry for the bad english.

---

<div class="post-metadata">

**Author:** ![jimmyalmeida](https://avatars.discourse-cdn.com/v4/letter/j/779978/32.png) [@jimmyalmeida](https://discuss.elastic.co/u/jimmyalmeida)\
**Post date:** [February 25, 2019, 3:08pm UTC](https://discuss.elastic.co/t/using-span-first-with-fuzziness/169604/2 "2019-02-25T15:08:24Z")

</div>

I was able to do it in the following way:

```
POST /produto/default/_search
{
  "_source": [
    "nome",
    "descricao",
    "categoria.nome"
  ],
  "query": {
    "bool": {
      "must": {
        "multi_match": {
          "query": "acucar",
          "tie_breaker": "1.0",
          "fields": [
            "nome",
            "descricao",
            "categoria.nome"
          ],
          "fuzziness": "auto"
        }
      },
      "should": [
        {
          "span_first": {
            "match": {
              "span_multi": {
                "match": {
                  "fuzzy": {
                      "nome": {"value": "acucar"}
                  }
                }
              }
            },
                  "end": 1
          }
        },
        {
          "span_first": {
            "match": {
              "span_multi": {
                "match": {
                  "fuzzy": {
                      "nome": {"value": "acucar"}
                  }
                }
              }
            },
                  "end": 2
          }
        }
      ]
    }
  }
}
```

---

<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 25, 2019, 3:08pm UTC](https://discuss.elastic.co/t/using-span-first-with-fuzziness/169604/3 "2019-03-25T15:08:27Z")

</div>

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