# Elastic 8 not search with hyphen

**URL:** https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824
**Category:** Elasticsearch
**Created:** [March 16, 2023, 8:26am UTC](https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824 "2023-03-16T08:26:00Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![suresh\_chaudhari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_chaudhari/32/106602_2.png) [@suresh\_chaudhari](https://discuss.elastic.co/u/suresh_chaudhari)
#### Post date: [March 16, 2023, 8:26am UTC](https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824/1 "2023-03-16T08:26:00Z")

</div>

I have documents with id fields  
{id:domain-837}{id:domain-838}  
these are automatically stored using mapping with data type keyword.

```auto
"id": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},

```

Still when I search it using  
MatchQuery,TermQuery I cannot get correct results.

```auto
{
    "query": {
        "match_phrase": {
         "id": "domain-838"
        }
    }
}
{
  "query": {
    "terms": {
      "_id": [
        "domain-837"
      ]
    }
  }
}

```

There is a problem with hypen.  
Has anyone solved this already can someone share how to define anyalyzer or what data type to use kindly share here

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [March 19, 2023, 9:22pm UTC](https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824/2 "2023-03-19T21:22:56Z")

</div>

Try using `id.keyword` instead, as your `id` field is a text and will be analysed where as the `.keyword` will be "raw".

---

<div class="post-metadata">

### Author: ![suresh\_chaudhari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_chaudhari/32/106602_2.png) [@suresh\_chaudhari](https://discuss.elastic.co/u/suresh_chaudhari)
#### Post date: [March 23, 2023, 6:23am UTC](https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824/3 "2023-03-23T06:23:07Z")

</div>

does not work with keyword it returns irrelevant result tried search search with term{"field.keyword":value}

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [March 23, 2023, 6:27am UTC](https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824/4 "2023-03-23T06:27:40Z")

</div>

Did you try the following (assuming `domain-837` is an existing value)?

```auto
{
  "query": {
    "term": {
      "id.keyword": {
        "value": "domain-837"
      }
    }
  }
}

```

What does the document you would expect to match look like?

---

<div class="post-metadata">

### Author: ![suresh\_chaudhari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_chaudhari/32/106602_2.png) [@suresh\_chaudhari](https://discuss.elastic.co/u/suresh_chaudhari)
#### Post date: [March 24, 2023, 6:01am UTC](https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824/5 "2023-03-24T06:01:39Z")

</div>

one more observation I am searching for elastic document UUIDS and I am searching for the text like pG4h5YYBbrFFY-P9s60F  
tried like what u shared using term but no use.  
I also need partial search say if I search only pG4h5YYBbrFFY or P9s60F

---

<div class="post-metadata">

### Author: ![suresh\_chaudhari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_chaudhari/32/106602_2.png) [@suresh\_chaudhari](https://discuss.elastic.co/u/suresh_chaudhari)
#### Post date: [March 27, 2023, 12:53pm UTC](https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824/6 "2023-03-27T12:53:54Z")

</div>

Hello helpful members of group finally i found what i need to achieve .I can achieve same thing using ngrams

---

<div class="post-metadata">

### Author: ![suresh\_chaudhari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_chaudhari/32/106602_2.png) [@suresh\_chaudhari](https://discuss.elastic.co/u/suresh_chaudhari)
#### Post date: [April 14, 2023, 6:50am UTC](https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824/7 "2023-04-14T06:50:40Z")

</div>

one more update  
use data type keyword and also use wildcard query to search for substrings.  
another thing is use lowercase filter for searching .when u index index using lowercase filter so that  
FOO foo will both be searched

---

<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: [May 12, 2023, 6:51am UTC](https://discuss.elastic.co/t/elastic-8-not-search-with-hyphen/327824/8 "2023-05-12T06:51:11Z")

</div>

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