Hyphen in alias name does not work


(MoD) #1

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"
    }
  }
}

(Christian Dahlqvist) #2

Can you please provide a full script replicating the issue?


(MoD) #3

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"
        }
    }

(David Pilato) #4

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

What is your mapping?


(MoD) #5
{
  "_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     

(David Pilato) #6

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

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


(MoD) #8

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.


(David Pilato) #9

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.


(MoD) #10

Yes! Reindex worked. Many thanks! :slight_smile:


(system) #11