Friday, November 19, 2021

Moving Persistence layer to ES

If you are looking for faster reads and writes in the background Elastic search framework suits it best. You don't need to add any caching layer and the server side response time would  meet the SLA  ie. below the permissible response time.

What you need to do is:

1. Create an Index

II. and attach it to an alias. That's it and BOOM!!!

 Creating Index

{

  "settings": {

    "index": {

      "number_of_shards": "2",

      "number_of_replicas": "3"

    }

  },

  "mappings": {

    "tweets": {

      "dynamic": "false",

      "dynamic_templates": [

        {

          "no_index_template": {

            "match": "*",

            "mapping": {

              "index": "no",

              "include_in_all": false

            }

          }

        }

      ],

      "properties": {

        "documentId": {

          "type": "keyword",

          "index": false

        },

        "tweetId": {

          "type": "keyword",

          "index": true

        }...

      }

    }

  }

}

How to add aliases 

POST_aliases{

  "actions": [

    {

      "add": {

        "index": "user_tweets-<commit-id>",

        "alias": "user_tweets"

      }

    },

    {

      "remove": {

        "index": "user_tweets-<old_commit-id>",

        "alias": "user_tweets"

      }

    }

  ]

}


No comments:

Post a Comment