# Fuzzy matching hashtag with Simple Query String Query

**URL:** https://discuss.elastic.co/t/fuzzy-matching-hashtag-with-simple-query-string-query/320416
**Category:** Elasticsearch
**Created:** [December 3, 2022, 5:49pm UTC](https://discuss.elastic.co/t/fuzzy-matching-hashtag-with-simple-query-string-query/320416 "2022-12-03T17:49:51Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kabcampbell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kabcampbell/32/137695_2.png) [@kabcampbell](https://discuss.elastic.co/u/kabcampbell)
#### Post date: [December 3, 2022, 5:49pm UTC](https://discuss.elastic.co/t/fuzzy-matching-hashtag-with-simple-query-string-query/320416/1 "2022-12-03T17:49:51Z")

</div>

I have an indexed field named "searchBucket" with the term "#revit" in it. Here is the analyzer applied to that field:

```auto
"default" : {
              "filter" : [
                "lowercase",
                "asciifolding",
                "english_stopwords_filter",
                "minimal_english_stemmer"
              ],
              "char_filter" : "html_strip",
              "type" : "custom",
              "tokenizer" : "uax_url_email"
            }

```

Via the Analyze API I've confirmed that this is the token that is generated:

```auto
{
  "tokens" : [
    {
      "token" : "revit",
      "start_offset" : 1,
      "end_offset" : 6,
      "type" : "<ALPHANUM>",
      "position" : 0
    }
  ]
}

```

I'm trying to search this field using the Simple Query String Query as follows:

```auto
"simple_query_string": {
                        "default_operator": "and",
                        "fields": ["searchBucket"],
                        "flags": "AND|OR|NOT|PREFIX|PHRASE|PRECEDENCE|WHITESPACE|FUZZY",
                        "fuzzy_prefix_length": 1,
                        "fuzzy_transpositions": true,
                        "lenient": true,
                        "query": "#reivt~",
                        "quote_field_suffix": ".exact"
                    }

```

As you can see, I'm trying to run a fuzzy query where the "i" and "v" are transposed. This does not match. However, if I remove the "#" from the beginning of the query and search "reivt~" it does match. Also if I remove the tilde from the query and search "#revit" it matches.

So it seems like perhaps using the tilde (fuzzy query) means that the field's analyzer isn't being applied? Is there anyone that can confirm this? Or can anyone give me a way to get the lucene query that is being generated under the hood for the simple query string query?

---

<div class="post-metadata">

### Author: ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)
#### Post date: [December 8, 2022, 9:12pm UTC](https://discuss.elastic.co/t/fuzzy-matching-hashtag-with-simple-query-string-query/320416/2 "2022-12-08T21:12:05Z")

</div>

> [@kabcampbell](#):
>
> can anyone give me a way to get the lucene query that is being generated under the hood for the simple query string query

You should be able to use the "\_validate/query" endpoint for this. Use the parameter "explain=true" as described [in the docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-validate.html) to see what query gets generated from this.

---

<div class="post-metadata">

### Author: ![kabcampbell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kabcampbell/32/137695_2.png) [@kabcampbell](https://discuss.elastic.co/u/kabcampbell)
#### Post date: [December 8, 2022, 10:44pm UTC](https://discuss.elastic.co/t/fuzzy-matching-hashtag-with-simple-query-string-query/320416/3 "2022-12-08T22:44:51Z")

</div>

Thank you Christophe, that was helpful. It appears that the `"fuzzy_prefix_length": 1` might be the problem. If that value is set to 0, the match succeeds. Since the "#" is the first character it seems to be left intact, even though the analyzer would typically strip that out. I guess I can try resetting that value back to the default of 0. It's still confusing to me why the analyzer doesn't get applied consistently - it's not like it ignores the first character completely. For example, if I type "Revit" the lowercase token filter still gets applied to that first character.

---

<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: [January 5, 2023, 10:45pm UTC](https://discuss.elastic.co/t/fuzzy-matching-hashtag-with-simple-query-string-query/320416/4 "2023-01-05T22:45:07Z")

</div>

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