# Hyphen in alias name does not work

**URL:** <https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368>\
**Category:** Elasticsearch\
**Created:** [February 22, 2016, 8:47am UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368 "2016-02-22T08:47:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mod/32/2459_2.png) [@MoD](https://discuss.elastic.co/u/MoD)\
**Post date:** [February 22, 2016, 8:47am UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/1 "2016-02-22T08:47:12Z")

</div>

Hi,

If i create an alias with a hyphen in it (ie. a-b), elastic search does not find any documents.

Is there a workaround?

```
http://example.com/a-b/
_search GET
{
  "query": {
    "queryString": {
      "query": "something"
    }
  }
}
```

---

<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:** [February 22, 2016, 11:26am UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/2 "2016-02-22T11:26:40Z")

</div>

Can you please provide a full script replicating the issue?

---

<div class="post-metadata">

**Author:** ![MoD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mod/32/2459_2.png) [@MoD](https://discuss.elastic.co/u/MoD)\
**Post date:** [February 22, 2016, 11:56am UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/3 "2016-02-22T11:56:43Z")

</div>

Ok, let me try (Most of the work is done by wrapper libraries):

1. create index "master"
2. create alias

```
http://example.com/master
_alias/a-b PUT
{
    "routing": "a-b",
    "filter": {
        "term": {
            "domain.name": "a-b"
        }
    }
}
```

1. Add any document with (domain.name="a-b"

2. Try to search:

```
{
  "query": {
    "queryString": {
      "query": "something"
    }
  }
}
```

Aha! When I write it this way; Might it be because of:

```
"filter": {
        "term": {
            "domain.name": "a-b"
        }
    }
```

---

<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:** [February 22, 2016, 3:09pm UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/4 "2016-02-22T15:09:50Z")

</div>

If you are using a default analyzer for your field, this won't work.

What is your mapping?

---

<div class="post-metadata">

**Author:** ![MoD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mod/32/2459_2.png) [@MoD](https://discuss.elastic.co/u/MoD)\
**Post date:** [February 22, 2016, 3:40pm UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/5 "2016-02-22T15:40:46Z")

</div>

```
{
  "_default_" :
  {
    "date_detection" : false,
    "properties" :
    {
      "@timestamp" :{ "type" : "date", "format" : "dateOptionalTime" },
      "domain": {
                "properties": {
                    "_hibernate_class": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "id": {
                        "type": "long"
                    }
                }
            }
    }
  }
}
```

and,

```
analysis:
    analyzer:
      default:
        type: custom
        tokenizer: standard        
        filter: [filename_word_delimiter, standard, lowercase, asciifolding]     
      filename_analyzer:
        type: custom
        tokenizer: lowercase
        filter: [filename_word_delimiter, filename_ngram]
    filter:
      filename_ngram:
        type: nGram
        min_gram: 3
        max_gram: 10
      filename_word_delimiter:
        type: word_delimiter
        generate_word_parts: true
        catenate_words: true
        catenate_numbers: true
        catenate_all: true
        split_on_case_change: false
        preserve_original: true
        split_on_numerics: false
        stem_english_possessive: true
```

---

<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:** [February 22, 2016, 3:45pm UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/6 "2016-02-22T15:45:10Z")

</div>

`domain.name` uses the default analyzer which lowercase, breaks your string into tokens...

You need to change its mapping and set `index: not_analyzed`.

---

<div class="post-metadata">

**Author:** ![MoD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mod/32/2459_2.png) [@MoD](https://discuss.elastic.co/u/MoD)\
**Post date:** [February 22, 2016, 4:08pm UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/8 "2016-02-22T16:08:33Z")

</div>

Unfortunately it did not work.

I changed the mapping to:

```
{
  "_default_" :
  {
    "date_detection" : false,
    "properties" :
    {
      "@timestamp" :{ "type" : "date", "format" : "dateOptionalTime" },
      "domain": {
                "properties": {
                    "_hibernate_class": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string",
                         "index": "not_analyzed"
                    },
                    "id": {
                        "type": "long"
                    }
                }
            }
    }
  }
}
```

Restarted elastic-search,  
Created another alias with hyphen,  
Added a document and searched.  
Finds the alias, does not find any document.

But thanks anyway, it is not an alias problem but a search problem. I can find a way to fix it.

---

<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:** [February 22, 2016, 4:23pm UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/9 "2016-02-22T16:23:58Z")

</div>

Yeah. You have to create a new index and reindex.

Look at the actual mapping for the index you already have.  
My guess is that it's still analyzed.

---

<div class="post-metadata">

**Author:** ![MoD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mod/32/2459_2.png) [@MoD](https://discuss.elastic.co/u/MoD)\
**Post date:** [February 22, 2016, 4:28pm UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/10 "2016-02-22T16:28:26Z")

</div>

Yes! Reindex worked. Many thanks! 🙂

---

<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:** [July 5, 2017, 11:14pm UTC](https://discuss.elastic.co/t/hyphen-in-alias-name-does-not-work/42368/11 "2017-07-05T23:14:28Z")

</div>


