DevOps Classroomnotes 26/Feb/2022

Elastic Search API Contd

  • Creating an Index:
    • Refer Here for the api detail
      Preview
    • Create mapping Refer Here
      Preview
    • Creating type mapping in an existing
      Preview
    • Now lets insert the document
      Preview
  • Getting all the documents from all indexes
    Preview
  • Getting all documents in one index
    Preview
  • Search all documents in multiple indexes
    Preview

Analyzers

  • All the fields which are of type text are analyzed by what is known as analyzer
  • The analyzer performs process of breaking up input character streams into terms. This happens twice
  • At the time of indexing
  • At the time of search
  • Components of Analyzer
    Preview
  • Character filter Refer Here
  • Tokenizer: The responisbility of tokenizer is to recieve a stream of characters and generate tokens. These tokens are used to build inverted index
    • Each token is roughly equivalent to word.
    • Refer Here
  • Token filter: Refer Here
    • Lowercase token filters: Replaces all the tokens in the input with their lowercase versions
    • Stop token filter: Remove stop words.
    • In English words like is, a, an, the, and

Experiments

  • We have inserted few documents into books index
{
  "took" : 523,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 11,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "books",
        "_id" : "IextNn8BqXWmOu20ef8W",
        "_score" : 1.0,
        "_source" : {
          "title" : "Atomic Habits",
          "category" : "selfhelp",
          "price" : 540
        }
      },
      {
        "_index" : "books",
        "_id" : "IuxuNn8BqXWmOu20DP8R",
        "_score" : 1.0,
        "_source" : {
          "title" : "Psychology of Money",
          "category" : "personal finance",
          "price" : 340
        }
      },
      {
        "_index" : "books",
        "_id" : "JuxvNn8BqXWmOu20eP8c",
        "_score" : 1.0,
        "_source" : {
          "title" : "Alchemist",
          "category" : "Self Help",
          "price" : 167
        }
      },
      {
        "_index" : "books",
        "_id" : "J-xvNn8BqXWmOu200v_T",
        "_score" : 1.0,
        "_source" : {
          "title" : "India that is Bharat",
          "category" : "History",
          "price" : 560
        }
      },
      {
        "_index" : "books",
        "_id" : "I-xuNn8BqXWmOu20bP9Z",
        "_score" : 1.0,
        "_source" : {
          "title" : "Never Forge",
          "category" : "Novel",
          "price" : 419
        }
      },
      {
        "_index" : "books",
        "_id" : "JOxuNn8BqXWmOu20y__J",
        "_score" : 1.0,
        "_source" : {
          "title" : "Word Power Made Easy",
          "category" : "Grammar",
          "price" : 89
        }
      },
      {
        "_index" : "books",
        "_id" : "KexwNn8BqXWmOu203f84",
        "_score" : 1.0,
        "_source" : {
          "title" : "Price Action Trading",
          "category" : "Finance",
          "price" : 335
        }
      },
      {
        "_index" : "books",
        "_id" : "KOxwNn8BqXWmOu20cf8s",
        "_score" : 1.0,
        "_source" : {
          "title" : "Nursery Rhymes",
          "category" : "Children",
          "price" : 149
        }
      },
      {
        "_index" : "books",
        "_id" : "H-w5Nn8BqXWmOu20ev8r",
        "_score" : 1.0,
        "_source" : {
          "title" : "Who Moved my cheese",
          "category" : "selfhelp"
        }
      },
      {
        "_index" : "books",
        "_id" : "IOw7Nn8BqXWmOu20Fv8R",
        "_score" : 1.0,
        "_source" : {
          "title" : "Your brain at work",
          "category" : "selfhelp",
          "author" : "David Rock"
        }
      }
    ]
  }
}

  • Querying Numeric data based on range
    Preview
  • Query on dates
GET /apachelogs/_search
{
    "query": {
        "range": {
            "generatedDate": {
                "gte": "01/01/2022",
                "lte": "26/02/2022",
                "format": "dd/MM/yyyy"
            }
        }
    }
}

GET /apachelogs/_search
{
    "query": {
        "range": {
            "generatedDate": {
                "gte": "now-7d",
                "lte": "now"
            }
        }
    }
}
  • Field Exists
    Preview
  • Searching text
    Preview
    Preview
    Preview
    Preview
    Preview
    Preview
    Preview
  • Explore the csv file and listout different activities which we can perform Refer Here
  • We would perform basic math aggregations
    • sum
    • average
    • price
    • min
    • max

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner