# ES not search with hyphen

**URL:** https://discuss.elastic.co/t/es-not-search-with-hyphen/300769
**Category:** Elasticsearch
**Created:** [March 26, 2022, 8:25pm UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769 "2022-03-26T20:25:29Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![EnJay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enjay/32/100715_2.png) [@EnJay](https://discuss.elastic.co/u/EnJay)
#### Post date: [March 26, 2022, 8:25pm UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/1 "2022-03-26T20:25:29Z")

</div>

Hello 🙂  
I can't figure out the problem at all. I have a field with a title. The name consists of a hyphen. This is: "usd-coin". I'm trying to search with this query:

```auto
{
    "sort": [
        {
            "time": "desc"
        }
    ],
    "query": {
        "bool": {
            "must": [
                {"term": {"currency": "usd-coin"}}
            ]
        }
    }
}

```

In the end, it doesn't look for anything. But as soon as I leave "usd" - everything will be found. I need search accuracy. Can you please tell me how I can search specifically for the query "usd-coin"?  
As far as I understand, the hyphen is reserved by the system. But how can this be bypassed?

I will be grateful for the answers.

---

<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: [March 26, 2022, 9:11pm UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/2 "2022-03-26T21:11:28Z")

</div>

Use a keyword datatype instead.

---

<div class="post-metadata">

### Author: ![EnJay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enjay/32/100715_2.png) [@EnJay](https://discuss.elastic.co/u/EnJay)
#### Post date: [March 26, 2022, 10:59pm UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/3 "2022-03-26T22:59:36Z")

</div>

Can you please tell me how to specify this?

---

<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: [March 27, 2022, 12:04am UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/4 "2022-03-27T00:04:20Z")

</div>

See [Keyword type family | Elasticsearch Guide [8.1] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html)

---

<div class="post-metadata">

### Author: ![EnJay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enjay/32/100715_2.png) [@EnJay](https://discuss.elastic.co/u/EnJay)
#### Post date: [March 27, 2022, 12:18am UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/5 "2022-03-27T00:18:22Z")

</div>

As I understand it, you need to recreate the partition and specify the mappings. But I already have a table. How can I search in my case?

---

<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: [March 27, 2022, 6:39am UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/6 "2022-03-27T06:39:51Z")

</div>

Yes. You need to reindex the data of you want to use the right mapping for your use case.

Here, as a workaround, you could maybe use a phrase query. Although this might work, be aware that it's a workaround and that you'd better use the right mapping.

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [March 27, 2022, 1:40pm UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/7 "2022-03-27T13:40:55Z")

</div>

You can try to create a runtime field with the `keyword` map for that specific field.

It would be something like this:

```auto
PUT your-index-name/
{
  "mappings": {
    "runtime": {
      "currency": {
        "type": "keyword"
      }
    }
  }
}

```

Be aware that runtime fields can impact the search performance in some cases, the best solution would indeed be a reindex, but maybe the runtime field can solve your problem quickly.

You can read more about runtime fields in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime.html).

---

<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: [March 27, 2022, 2:20pm UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/8 "2022-03-27T14:20:26Z")

</div>

OMG! I forgot about this one. Thanks @leandrojmp !

---

<div class="post-metadata">

### Author: ![EnJay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/enjay/32/100715_2.png) [@EnJay](https://discuss.elastic.co/u/EnJay)
#### Post date: [March 30, 2022, 12:54am UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/9 "2022-03-30T00:54:42Z")

</div>

Thanks a lot 🙂

---

<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 27, 2022, 12:55am UTC](https://discuss.elastic.co/t/es-not-search-with-hyphen/300769/10 "2022-04-27T00:55:09Z")

</div>

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