# Analyzer to support slash "/" in Query String search

**URL:** <https://discuss.elastic.co/t/analyzer-to-support-slash-in-query-string-search/365053>\
**Category:** Elastic Search\
**Created:** [August 16, 2024, 6:09pm UTC](https://discuss.elastic.co/t/analyzer-to-support-slash-in-query-string-search/365053 "2024-08-16T18:09:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valerio\_Barbera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/valerio_barbera/32/136837_2.png) [@Valerio\_Barbera](https://discuss.elastic.co/u/Valerio_Barbera)\
**Post date:** [August 16, 2024, 6:09pm UTC](https://discuss.elastic.co/t/analyzer-to-support-slash-in-query-string-search/365053/1 "2024-08-16T18:09:55Z")

</div>

Hi,  
I have an index that store an "url" field that contains "/" (forward slash) on which I execute only `query_string` searches.

Unfortunately the slash "/" seems to have side effects on query\_string search because of the analyzer on the field. The same when you use the wildcard character "\*".

I don't get any errors by the query\_string search, just a wrong or empty result.

So my question is: What type of mapping I should use for a field to support the slash "/" as a normal character for a field used only on Query String searches?

Something similar was discussed on this post:

> <https://stackoverflow.com/questions/44981143/how-to-use-slash-in-kibana-discovery>

But no solutions.

Currently I have the configuration below for the index:

Field Mapping

```auto
{
    "name": {
        "type": "text"
    },
    "hash": {
        "type": "keyword"
    },
    "duration": {
        "type": "float"
    }
}

```

Settings

```auto
{
    "analysis": {
        "char_filter": {
            "replace": {
                "type": "mapping",
                "mappings": [
                    "&=> and "
                ]
            }
        },
        "filter": {
            "word_delimiter": {
                "type": "word_delimiter",
                "split_on_numerics": false,
                "split_on_case_change": true,
                "generate_word_parts": true,
                "generate_number_parts": true,
                "catenate_all": true,
                "preserve_original": true,
                "catenate_numbers": true
            }
        },
        "analyzer": {
            "default": {
                "type": "custom",
                "char_filter": [
                    "html_strip",
                    "replace"
                ],
                "tokenizer": "whitespace",
                "filter": [
                    "lowercase",
                    "word_delimiter"
                ]
            }
        }
    }
}

```

What analyzer configuration should be used to make Query String works also with "/" and "\*"?

---

<div class="post-metadata">

**Author:** ![czek0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/czek0/32/136480_2.png) [@czek0](https://discuss.elastic.co/u/czek0)\
**Post date:** [August 19, 2024, 7:33am UTC](https://discuss.elastic.co/t/analyzer-to-support-slash-in-query-string-search/365053/2 "2024-08-19T07:33:11Z")

</div>

Hi,  
I have a a question, are you trying to strip the html from the urls but keep the '/' characters. Or keep the origional mappings of urls to be html stripped but on search, allow the user to search '/'?

---

<div class="post-metadata">

**Author:** ![Valerio\_Barbera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/valerio_barbera/32/136837_2.png) [@Valerio\_Barbera](https://discuss.elastic.co/u/Valerio_Barbera)\
**Post date:** [August 19, 2024, 8:00am UTC](https://discuss.elastic.co/t/analyzer-to-support-slash-in-query-string-search/365053/3 "2024-08-19T08:00:28Z")

</div>

URLs do not contains html, just the path of the endpoint with "/".

I'm not very aware of what the analyzer is doing since I used a suggested configuration from other developers.

I tried to learn more about analyzers on the Elastic documentation, but it seems quite complicated. Maybe I don't need all this index settings but I don't know the possible side effects so I tried to ask here.

Maybe some videos, articles, or other resources could be helpful.

---

<div class="post-metadata">

**Author:** ![czek0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/czek0/32/136480_2.png) [@czek0](https://discuss.elastic.co/u/czek0)\
**Post date:** [August 19, 2024, 8:56am UTC](https://discuss.elastic.co/t/analyzer-to-support-slash-in-query-string-search/365053/4 "2024-08-19T08:56:45Z")

</div>

oh okay I see,  
You can try using the keyword tokenizer. This will treat the url as an entire word and keep all '/', ' ' and '\*' special characters. You can find an example below or in the docs:

> **[Keyword tokenizer | Elasticsearch Guide \[8.15\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-keyword-tokenizer.html)**

```auto
# Test Keyword Tokenizer
POST _analyze
{
  "tokenizer": "keyword",
  "text": "New York*/"
}
# Example setup
 PUT /url_index
{
  "settings": {
    "analysis": {
      "analyzer": {
        "url_analyzer": {
          "type": "custom",
          "tokenizer": "keyword", 
          "filter": [
            "lowercase" 
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "url": {
        "type": "text",
        "analyzer": "url_analyzer"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Valerio\_Barbera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/valerio_barbera/32/136837_2.png) [@Valerio\_Barbera](https://discuss.elastic.co/u/Valerio_Barbera)\
**Post date:** [August 19, 2024, 9:22am UTC](https://discuss.elastic.co/t/analyzer-to-support-slash-in-query-string-search/365053/5 "2024-08-19T09:22:54Z")

</div>

> [@czek0](#):
>
> `keyword`

Thank you for the feedback. I'm going to try.

---

<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:** [September 16, 2024, 9:23am UTC](https://discuss.elastic.co/t/analyzer-to-support-slash-in-query-string-search/365053/6 "2024-09-16T09:23:14Z")

</div>

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