Click here to Skip to main content
13,665,017 members
Rate this:
 
Please Sign up or sign in to vote.
I have tried Index Aliases | Elasticsearch Reference [2.0] | Elastic[^], but what if i need to create alias at time when documents are added into index based on values passed to insert. here in my case that value is customer type, so i want to create an alias which will be added into index based on value passed on Customer Type, If value is different, It should create a new alias other wise won't, can any one has idea about it?

What I have tried:

index name=customeinfo
index type=Customer


Index Mapping

{
  "customeinfo": {
    "mappings": {
      "Customer": {
        "properties": {
          "Id": {
            "type": "long"
          },
          "Name": {
            "type": "string"
          },
          "Type": {
            "type": "string"
          },
          "type": {
            "type": "string"
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1526625709246",
        "number_of_shards": "1",
        "number_of_replicas": "1",
        "uuid": "uEbfvBvTRK-AGzBaQWqu-Q",
        "version": {
          "created": "2030399"
        }
      }
    },
    "warmers": {}
  }
}


when a new document is added in Elastic index like
{
  "Id": 1,
  "Name": "Alice",
  "type": "premium"
}


then a new alias should be added and my index would become like
{
  "customeralias": {
    "aliases": {
      "premiumcustomeralias": {
        "filter": {
          "term": {
            "type": "premium"
          }
        }
      }
    },
    "mappings": {},
    "settings": {},
    "warmers": {}
  }
}


again a new document is added in Elastic index like
{
  "Id": 2,
  "Name": "Bob",
  "type": "basic"
}


then again a new alias should be added and my index and index would become like
{
  "customeralias": {
    "aliases": {
      "premiumcustomeralias": {
        "filter": {
          "term": {
            "type": "premium"
          }
        }
      },
      "basiccustomeralias": {
        "filter": {
          "term": {
            "type": "basic"
          }
        }
      }
    },
    "mappings": {},
    "settings": {},
    "warmers": {}
  }
}
Posted 17-May-18 23:53pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180810.1 | Last Updated 18 May 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100