# How to perform full text search for a numberic field?

**URL:** <https://discuss.elastic.co/t/how-to-perform-full-text-search-for-a-numberic-field/146467>\
**Category:** Elasticsearch\
**Created:** [August 29, 2018, 5:51am UTC](https://discuss.elastic.co/t/how-to-perform-full-text-search-for-a-numberic-field/146467 "2018-08-29T05:51:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![betty](https://avatars.discourse-cdn.com/v4/letter/b/0ea827/32.png) [@betty](https://discuss.elastic.co/u/betty)\
**Post date:** [August 29, 2018, 5:51am UTC](https://discuss.elastic.co/t/how-to-perform-full-text-search-for-a-numberic-field/146467/1 "2018-08-29T05:51:59Z")

</div>

Hi experts,

As the title described, I need to perform full-text search for a field with type "long".

For example:  
{id: 100009078}

I need to get it when I search for "78".

Since the mapping cannot be changed once created, how can we do full-text search for the numeric field like we do for the text field?

Any advice is appreciated!

---

<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:** [August 29, 2018, 12:57pm UTC](https://discuss.elastic.co/t/how-to-perform-full-text-search-for-a-numberic-field/146467/2 "2018-08-29T12:57:06Z")

</div>

> [@betty](#):
>
> Since the mapping cannot be changed once created, how can we do full-text search for the numeric field like we do for the text field?

You can't. Full-text search capabilities require building the datastructures needed for a speedy lookup (i.e. the inverted index), and this is done at index time. So if you need to find documents based on prefixes or suffixes like you describe above, you need to index them again with the appropriate field type. You can use [multi-fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html) if you need both numeric and text search, and you can use the reindex api to move your existing index to a new one with the right mapping, but this will still require indexing all documents again (i.e. building the index structure). No way around this.

Mind you that the above example still won't work with the default [analyzers](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-analyzers.html) since you are looking for suffixes but the default analyzers will treat the whole number as a single token. You need to look into something like the [edge analyzer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html) or possibly the [reverse token filter](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-reverse-tokenfilter.html) in conjunction with the [prefix query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html). I would suggest starting with the edge ngrams since I assume they will be faster than the prefix queries.

---

<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 26, 2018, 12:57pm UTC](https://discuss.elastic.co/t/how-to-perform-full-text-search-for-a-numberic-field/146467/3 "2018-09-26T12:57:06Z")

</div>

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