# Query on numeric data type

**URL:** <https://discuss.elastic.co/t/query-on-numeric-data-type/78313>\
**Category:** Elasticsearch\
**Created:** [March 13, 2017, 8:46am UTC](https://discuss.elastic.co/t/query-on-numeric-data-type/78313 "2017-03-13T08:46:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![muthucse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muthucse/32/45217_2.png) [@muthucse](https://discuss.elastic.co/u/muthucse)\
**Post date:** [March 13, 2017, 8:46am UTC](https://discuss.elastic.co/t/query-on-numeric-data-type/78313/1 "2017-03-13T08:46:11Z")

</div>

Is it possible to do a wildcard search in a long or a numeric field in elasticsearch ?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 13, 2017, 9:16pm UTC](https://discuss.elastic.co/t/query-on-numeric-data-type/78313/2 "2017-03-13T21:16:02Z")

</div>

Hey,

wildcard query works on terms only. Can you explain your use-case? Wouldnt ranges work better, or if not, maybe another index time data structure?

--Alex

---

<div class="post-metadata">

**Author:** ![muthucse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muthucse/32/45217_2.png) [@muthucse](https://discuss.elastic.co/u/muthucse)\
**Post date:** [March 16, 2017, 6:31am UTC](https://discuss.elastic.co/t/query-on-numeric-data-type/78313/3 "2017-03-16T06:31:18Z")

</div>

The problem is, if the long field has value 120450, 120445, 120656. Please find the query below.

_{"from":0,"size":10,"query":{"nested":{"query":{"bool":{"must":[{"query\_string":{"query":"120","fields":["alist.articleId"]}}]}},"path":"alist"}}}_

The response should return all the three documents which has partial match for 120. **Is it possible to achieve this in long or a numeric field ?**

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 16, 2017, 7:57am UTC](https://discuss.elastic.co/t/query-on-numeric-data-type/78313/4 "2017-03-16T07:57:21Z")

</div>

Hey,

you could index the number as a string field as well and then use the wildcard query (which you did not use in your example, slightly confused).

--Alex

---

<div class="post-metadata">

**Author:** ![muthucse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/muthucse/32/45217_2.png) [@muthucse](https://discuss.elastic.co/u/muthucse)\
**Post date:** [March 16, 2017, 8:05am UTC](https://discuss.elastic.co/t/query-on-numeric-data-type/78313/5 "2017-03-16T08:05:51Z")

</div>

Alex, I should not change the mapping of the index. Can you please let me know is it possible to achieve using numeric fields ?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 16, 2017, 8:21am UTC](https://discuss.elastic.co/t/query-on-numeric-data-type/78313/6 "2017-03-16T08:21:28Z")

</div>

Hey,

no it is not. You could index a field as string and number if you need - I do not see why this is a problem. Check out the Elasticsearch documentation about the [fields](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/multi-fields.html) parameter in mappings.

--Alex

---

<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:** [April 13, 2017, 8:21am UTC](https://discuss.elastic.co/t/query-on-numeric-data-type/78313/7 "2017-04-13T08:21:37Z")

</div>

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