# How to know if search query contains numbers

**URL:** <https://discuss.elastic.co/t/how-to-know-if-search-query-contains-numbers/105403>\
**Category:** Elasticsearch\
**Created:** [October 26, 2017, 10:23am UTC](https://discuss.elastic.co/t/how-to-know-if-search-query-contains-numbers/105403 "2017-10-26T10:23:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karolinebryn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karolinebryn/32/17095_2.png) [@Karolinebryn](https://discuss.elastic.co/u/Karolinebryn)\
**Post date:** [October 26, 2017, 10:23am UTC](https://discuss.elastic.co/t/how-to-know-if-search-query-contains-numbers/105403/1 "2017-10-26T10:23:19Z")

</div>

I posted a [question](https://discuss.elastic.co/t/how-to-handle-search-query-with-both-words-and-numbers/104054) earlier, but nobody seems to be able to answer it so I am trying a gain with a different explanation.

Is there a way to know if a search query contains numbers (or not words)?

Take the following example;

```
{
  "query": {
    "match": {
      "title": "vacation 2017"
    }
  }
}

```

Is there some way to set up either the query or the mappings/settings in the index, so that when people search for "vacation 2017" the search engine will suggest documents that contains both terms OR documents that contains ONLY the word and not the year? The year is in this case only relevant in combination with the word. It has no meaning on its own.

---

<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:** [October 27, 2017, 3:28pm UTC](https://discuss.elastic.co/t/how-to-know-if-search-query-contains-numbers/105403/2 "2017-10-27T15:28:35Z")

</div>

hey,

you could index your data in a field which drops all number, so you only search in text. queries have to hit in this field and by using a bool query with a should clause you could score up those documents which have 'vacation 2017' as well.

hope that makes a little bit sense.

--Alex

---

<div class="post-metadata">

**Author:** ![Karolinebryn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karolinebryn/32/17095_2.png) [@Karolinebryn](https://discuss.elastic.co/u/Karolinebryn)\
**Post date:** [October 30, 2017, 1:36pm UTC](https://discuss.elastic.co/t/how-to-know-if-search-query-contains-numbers/105403/3 "2017-10-30T13:36:38Z")

</div>

I'm not 100% sure what you mean. You mean that I have to write my own code that removes numbers before I index the document?

I was hoping that I could create an analyzer that would do this for me. The same way that you can create analyzers with filters that "removes" stopwords.

---

<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:** [November 27, 2017, 1:36pm UTC](https://discuss.elastic.co/t/how-to-know-if-search-query-contains-numbers/105403/4 "2017-11-27T13:36:43Z")

</div>

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