# Edge n-gram search for terms with optional spaces

**URL:** https://discuss.elastic.co/t/edge-n-gram-search-for-terms-with-optional-spaces/330018
**Category:** Elasticsearch
**Created:** [April 14, 2023, 1:48pm UTC](https://discuss.elastic.co/t/edge-n-gram-search-for-terms-with-optional-spaces/330018 "2023-04-14T13:48:43Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![kedomingo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kedomingo/32/141255_2.png) [@kedomingo](https://discuss.elastic.co/u/kedomingo)
#### Post date: [April 14, 2023, 4:08pm UTC](https://discuss.elastic.co/t/edge-n-gram-search-for-terms-with-optional-spaces/330018/4 "2023-04-14T16:08:31Z")

</div>

I got another insight from another thread here: [Search by digits doesn't work with edge\_ngram - #2 by dadoonet](https://discuss.elastic.co/t/search-by-digits-doesnt-work-with-edge-ngram/134433/2)

I tried analyze and it is removing the numbers from my query. I replaced the tokenizer with "whitespace" instead

I also decided to have 2 fields: original and term, and keeping term.autocomplete as in the example. Both fields are searched with no boosting and it seems to work as expected now.

```auto
PUT /searches

{
  "settings": {
    "analysis": {
      "analyzer": {
        "autocomplete": {
          "tokenizer": "autocomplete",
          "filter": [
            "lowercase"
          ]
        },
        "autocomplete_search": {
          "type" : "custom",
          "tokenizer": "whitespace",
          "filter": "lowercase"
        }
      },
      "tokenizer": {
        "autocomplete": {
          "type": "edge_ngram",
          "min_gram": 1,
          "max_gram": 10,
          "token_chars": []
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "original": {
        "type": "text"
      },
      "term": {
        "type": "text",
        "fields": {
          "autocomplete": {
            "type": "text",
            "analyzer": "autocomplete",
            "search_analyzer": "autocomplete_search"
          }
        }
      }
    }
  }
}

PUT /searches/_doc/1
{
  "original": "Pentium 4",
  "term": "pentium4"
}

PUT /searches/_doc/2
{
  "original": "Pentium 3 Intel Processor",
  "term": "pentium3intelprocessor"
}

GET /searches/_search
{
  "query": {
    "multi_match": {
      "query": "pentium3",
      "fields": ["term.autocomplete", "original"],
      "operator": "and"
    }
  }
}

```

---

_[View the full topic](https://discuss.elastic.co/t/edge-n-gram-search-for-terms-with-optional-spaces/330018)._
