# Index numbers in strings as numeric and words

**URL:** <https://discuss.elastic.co/t/index-numbers-in-strings-as-numeric-and-words/336666>\
**Category:** Elasticsearch\
**Created:** [June 22, 2023, 10:19am UTC](https://discuss.elastic.co/t/index-numbers-in-strings-as-numeric-and-words/336666 "2023-06-22T10:19:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Lockwood](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@Michael\_Lockwood](https://discuss.elastic.co/u/Michael_Lockwood)\
**Post date:** [June 22, 2023, 10:19am UTC](https://discuss.elastic.co/t/index-numbers-in-strings-as-numeric-and-words/336666/1 "2023-06-22T10:19:44Z")

</div>

Hi, I have a requirement where I want to search for numbers within a string by both the numeric value (e.g. 3) and the string value (e.g. "three").

For example given the following index configuration

```auto
PUT number-test
{
  "mappings": {
    "properties": {
      "text": {
        "type": "text", 
        "analyzer": "standard"
      }
    }
  }
}

PUT number-test/_doc/1
{
  "text": "this is the number three"
}

PUT number-test/_doc/2
{
  "text": "this is the number 3"
}

PUT number-test/_doc/3
{
  "text": "this is the number 2"
}

PUT number-test/_doc/4
{
  "text": "this is the number two"
}

```

Then the following search would return both documents 1 & 2.

```auto
POST number-test/_search
{
  "query": {
    "match": {
      "text": "three"
    }
  }
}

```

I know I could probably achieve this via synonyms. But I was hoping there was an automated way to do it (maybe through an additional tokenizer etc) that wouldn't require me having to configure every possible number as a synonym.

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 22, 2023, 10:33am UTC](https://discuss.elastic.co/t/index-numbers-in-strings-as-numeric-and-words/336666/2 "2023-06-22T10:33:45Z")

</div>

I don't think there is another solution than the synonyms or a [Pattern replace](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pattern-replace-charfilter.html).

May be using the new Machine Learning features for text would work though. But note that is part of the commercial license.

---

<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:** [July 20, 2023, 10:34am UTC](https://discuss.elastic.co/t/index-numbers-in-strings-as-numeric-and-words/336666/3 "2023-07-20T10:34:14Z")

</div>

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