0
votes

Is is any way in elastic to store index template per alias. I mean create Index with multiple aliases (alias1 ,alias2 ..) and attach different template to each of them. Then perform Index/Search docs on specific alias.

The reason I'm doing so due to multiple different data-structure (up to 50 types) of documents.

What I did so far is :

 1. PUT /dynamic_index

 2. POST /_aliases
       { "actions" : [
        { "add" : { "index" : "dynamic_index", "alias" : "alias_type1" } },
        { "add" : { "index" : "dynamic_index", "alias" : "alias_type2" } },
        { "add" : { "index" : "dynamic_index", "alias" : "alias_type3" } }
        ]}
 3. 

    PUT_template/template1 {
      "index_patterns": [
        "dynamic_index"
      ],
      "mappings": {
        "dynamic_templates": [
          {
            "strings_as_keywords": {
              "match_mapping_type": "string",
              "mapping": {
                "type": "text",
                "analyzer": "standard",
                "copy_to": "_all",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "normalizer": "lowercase_normalizer"
                  }
                }
              }
            }
          }
        ],
        "properties": {
          "source": {
            "type": "keyword"
          }
        }
      },
      "aliases": {
        "alias_type1": {
        }
      }
    }

4. same way to alias_type2 , alias_type3 but different fields ...

Indexing/Search : Trying create and search docs per alias like in example:

   POST alias_type1/_doc
    {
      "source": "foo" 
     , .....
      
    }

    POST alias_type2/_doc
    {
      "source": "foo123" 
     , .....
      
    }
    
    GET alias_type1/_search
    {
      "query": {
        "match_all": {}
      }
    }
  GET alias_type2/_search
    {
      "query": {
        "match_all": {}
      }
    }

What I see actually that even if I index documents per alias, when searching I don't see result per alias ,all results are same on alias_type1,2 and even on index.

Any way I can achieve separation logic on each alias in terms of searches/index docs per type (alias) ?

Any ideas ?

1

1 Answers

0
votes

You can’t have separate mapping for aliases pointing to the same index! Aliases are like virtual link pointing to a index so if your aliases pointing to same index you will get the same result back. If you want to have different mapping based on your data structure you will need to creat multiple indices.

Update You also can use custom routing based on a field for more information you can check Elastic official documentation here.