# How to search for terms containing hyphen (-) on \_all field?

**URL:** <https://discuss.elastic.co/t/how-to-search-for-terms-containing-hyphen-on--all-field/81335>\
**Category:** Elasticsearch\
**Created:** [April 5, 2017, 3:56pm UTC](https://discuss.elastic.co/t/how-to-search-for-terms-containing-hyphen-on--all-field/81335 "2017-04-05T15:56:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptrussart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ptrussart/32/25648_2.png) [@ptrussart](https://discuss.elastic.co/u/ptrussart)\
**Post date:** [April 5, 2017, 3:56pm UTC](https://discuss.elastic.co/t/how-to-search-for-terms-containing-hyphen-on--all-field/81335/1 "2017-04-05T15:56:06Z")

</div>

Hello,

I have an issue searching a term containing hyphens on the `_all` field. I have also tried with a custom `_all` field but I have the same results.

I have configured my index like this, using a `filter` with a `"type" : "word_delimiter"` and `"preserve_original": "true"` .

```
PUT my_index
POST my_index/_close
PUT my_index/_settings
{
   "index": {
      "analysis": {
      	"filter" : {
            "my_word_delimiter" : {
                "type" : "word_delimiter",
                "preserve_original": "true"
            }   
        },
         "analyzer": {
            "my_analyzer": {
               "type": "custom",
               "tokenizer": "standard",
               "filter": [
                  "standard",
                  "lowercase",
                  "stop",
                  "my_word_delimiter"
               ]
            }
         }
   }
 }
}

POST my_index/_open

PUT my_index/my_item/_mapping
{
   "my_item": {
  "_all": {
     "analyzer": "my_analyzer"
  },
  "properties": {
     "name": {
        "type": "keyword"
     },
     "title": {
        "type": "keyword"
     },
     "identifier": {
        "type": "keyword"
     }
  }
   }
}

```

Now if I put items in my index like this :

```
PUT my_index/my_item/001
{
    "name" : "doc_num_01234",
    "title" : "doc-num-01234"
}

```

And then, I try to search on it, if I search for `doc_num_01234` in `_all`, it works fine.  
But if I search for `doc-num-01234` I do not have results.

This :

```
POST my_index/_search
{
   "query": {
      "term": {
         "_all": "doc-num-01234"
      }
   }
}

```

returns nothing.

What can I do to retrieve the proper values ?

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [April 5, 2017, 11:06pm UTC](https://discuss.elastic.co/t/how-to-search-for-terms-containing-hyphen-on--all-field/81335/2 "2017-04-05T23:06:20Z")

</div>

Your analyzer isn't doing what you think it is, it's removing the `-`, See:

```
DELETE my_index

PUT my_index
{
  "index": {
    "analysis": {
      "filter" : {
        "my_word_delimiter" : {
          "type" : "word_delimiter",
          "preserve_original": "true"
        }   
      },
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "standard",
            "lowercase",
            "stop",
            "my_word_delimiter"
          ]
        }
      }
    }
  }
}

POST /my_index/_analyze
{
  "field": "_all",
  "text": "doc-num-01234"
}

POST /my_index/_analyze
{
  "tokenizer": "standard",
  "text": "doc-num-01234"
}
```

---

<div class="post-metadata">

**Author:** ![ptrussart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ptrussart/32/25648_2.png) [@ptrussart](https://discuss.elastic.co/u/ptrussart)\
**Post date:** [April 6, 2017, 7:34am UTC](https://discuss.elastic.co/t/how-to-search-for-terms-containing-hyphen-on--all-field/81335/3 "2017-04-06T07:34:36Z")

</div>

Thank you for your answer.

Changing my `tokenizer` to `whitespace` solved my issue 👍

```
PUT my_index
POST my_index/_close
PUT my_index/_settings
{
   "index": {
      "analysis": {
          "filter" : {
            "my_word_delimiter" : {
                "type" : "word_delimiter",
                "preserve_original": "true"
            }   
        },
         "analyzer": {
            "my_analyzer": {
               "type": "custom",
               "tokenizer": "whitespace",
               "filter": [
                  "standard",
                  "lowercase",
                  "stop",
                  "my_word_delimiter"
               ]
            }
         }
   }
 }
}

POST my_index/_open
```

---

<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 4, 2017, 7:34am UTC](https://discuss.elastic.co/t/how-to-search-for-terms-containing-hyphen-on--all-field/81335/4 "2017-05-04T07:34:47Z")

</div>

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