# Handling Punctuation in multi\_match query

**URL:** <https://discuss.elastic.co/t/handling-punctuation-in-multi-match-query/198318>\
**Category:** Elasticsearch\
**Created:** [September 5, 2019, 9:36pm UTC](https://discuss.elastic.co/t/handling-punctuation-in-multi-match-query/198318 "2019-09-05T21:36:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cannon\_Moyer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cannon_moyer/32/46269_2.png) [@Cannon\_Moyer](https://discuss.elastic.co/u/Cannon_Moyer)\
**Post date:** [September 5, 2019, 9:36pm UTC](https://discuss.elastic.co/t/handling-punctuation-in-multi-match-query/198318/1 "2019-09-05T21:36:04Z")

</div>

I have a query where I search for a product name field. My products might contain punctuation and my queries might contain the punctuation as well. Given the following product title "CenterG 5.3 Drive Belt for model number 4421" and the query "Centerg 5.3 Drive Belt" I can obtain the results I would expect.

However, if the query contains no punctuation, the "CenterG 5.3 Drive Belt for model number 4421" product does not show up in the results. Instead other less relevant products that simply have "53" in the title render first.

I have tried both the english and standard analyzers but I believe I need to create my own analyzer and tokenizer but I am unsure what configuration settings I should use. The english analyzer works best so far with my data-set the only issue is the punctuation.

Here is my index:

```
{:properties=>{:name=>{:type=>"text", :analyzer=>"english"}}

```

And my query:

```
 {
        query: {
            bool: {
                should: 
                   {
                        multi_match:{
                            fields: ["name"],
                            query: "#{query}"
                        }
                    }
             }
          }

    }
```

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [September 8, 2019, 4:59pm UTC](https://discuss.elastic.co/t/handling-punctuation-in-multi-match-query/198318/2 "2019-09-08T16:59:28Z")

</div>

You could create a custom analyzer that uses the [mapping character filter](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-mapping-charfilter.html) to remove all characters you would like to ignore, like the `.` character.

For example, if you created your index like this:

```auto
PUT my_index
{
  "settings": {
    "analysis": {
      "char_filter": {
        "my_char_filter": {
          "type": "mapping",
          "mappings": [
            ". =>"
          ]
        }
      },
      "analyzer": {
        "my_analyzer": {
          "char_filter": [
            "my_char_filter"
          ],
          "tokenizer": "standard",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "analyzer": "my_analyzer"
      }
    }
  }
}

```

You could then query for `5.3` or `53` and get the exact same document containing `"CenterG 5.3 Drive Belt for model number 4421"`:

```auto
PUT my_index/_doc/1
{
  "name": "CenterG 5.3 Drive Belt for model number 4421"
}

GET my_index/_search
{
  "query": {
    "match": {
      "name": "5.3"
    }
  }
}

GET my_index/_search
{
  "query": {
    "match": {
      "name": "53"
    }
  }
}

```

---

<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:** [October 6, 2019, 4:59pm UTC](https://discuss.elastic.co/t/handling-punctuation-in-multi-match-query/198318/3 "2019-10-06T16:59:37Z")

</div>

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