Skip to content

Instantly share code, notes, and snippets.

@omarsar
Last active October 23, 2018 06:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarsar/be53d59fa8a6ca562fda00d15f4c2e0a to your computer and use it in GitHub Desktop.
Save omarsar/be53d59fa8a6ca562fda00d15f4c2e0a to your computer and use it in GitHub Desktop.
Kibana Dev Tools Cheat Sheet

Kibana Cheat Sheet

Some helpful commands for Kibana using the Dev Tools feature:

GET _all

GET twitter/tweet/_count

GET my_index

DELETE my_index

DELETE twitter

PUT twitter
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0,
      "mapper.dynamic": false
    },
    "analysis": {
      "analyzer": {
        "nlp_analyzer": {
          "type": "custom",
          "tokenizer": "tweeter_tokenizer",
          "filter": ["lowercase"]
        }
      },
      "tokenizer": {
        "tweeter_tokenizer": {
          "type": "pattern",
          "pattern": "(http?\\S*\\w+|\\w+|\\S*[\\S*])",
          "group": 1
        }
      }
    }

  },
  "mappings": {
    "author": {
      "_all": {
        "enabled": false
      },
      "dynamic": "false",
      "properties": {
        "author_description": {
          "type": "text",
          "fields": {
            "english": {
              "type": "text",
              "analyzer": "english",
              "term_vector": "yes"
            },
            "nlp": {
              "type": "text",
              "analyzer": "nlp_analyzer",
              "term_vector": "yes"
            },
            "standard": {
              "type": "text",
              "analyzer": "standard",
              "term_vector": "yes"
            },
            "english_token_number": {
              "type": "token_count",
              "analyzer": "english"
            },
            "nlp_token_number": {
              "type": "token_count",
              "analyzer": "nlp_analyzer"
            },
            "standard_token_number": {
              "type": "token_count",
              "analyzer": "standard"
            }
          }
        },
        "is_author_protected": {
          "type": "boolean"
        },
        "author_location": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword"
            },
            "english": {
              "type": "text",
              "analyzer": "english",
              "term_vector": "yes"
            },
            "nlp": {
              "type": "text",
              "analyzer": "nlp_analyzer",
              "term_vector": "yes"
            },
            "standard": {
              "type": "text",
              "analyzer": "standard",
              "term_vector": "yes"
            },
            "english_token_number": {
              "type": "token_count",
              "analyzer": "english"
            },
            "nlp_token_number": {
              "type": "token_count",
              "analyzer": "nlp_analyzer"
            },
            "standard_token_number": {
              "type": "token_count",
              "analyzer": "standard"
            }
          }
        },
        "author_lang": {
          "type": "keyword"
        },
        "author_account_creation": {
          "type": "date"
        },
        "is_author_verified": {
          "type": "boolean"
        },
        "author_id": {
          "type": "keyword"
        },
        "author_name": {
          "type": "keyword"
        },
        "author_pseudo": {
          "type": "keyword"
        },
        "author_friends_count": {
          "type": "integer"
        },
        "author_followers_count": {
          "type": "integer"
        },
        "inserted_in_es_at": {
          "type": "date"
        }
      }
    },
    "tweet": {
      "_parent": {
        "type": "author"
      },
      "dynamic": "false",
      "_all": {
        "enabled": false
      },
      "properties": {
        "sentiment" : {
          "type": "keyword"
        },
        "tweet_coordinates": {
          "type": "geo_point"
        },
        "tweet_id": {
          "type": "keyword"
        },
        "retweet_count": {
          "type": "integer"
        },
        "original_favorite_count": {
          "type": "integer"
        },
        "tweet_created_at": {
          "type": "date"
        },
        "is_a_retweet": {
          "type": "boolean"
        },
        "original_tweet_id": {
          "type": "keyword"
        },
        "favorite_count": {
          "type": "integer"
        },
        "tweet_content": {
          "type": "text",
          "fields": {
            "english": {
              "type": "text",
              "analyzer": "english",
              "term_vector": "yes"
            },
            "nlp": {
              "type": "text",
              "analyzer": "nlp_analyzer",
              "term_vector": "yes"
            },
            "standard": {
              "type": "text",
              "analyzer": "standard",
              "term_vector": "yes"
            },
            "english_token_number": {
              "type": "token_count",
              "analyzer": "english"
            },
            "nlp_token_number": {
              "type": "token_count",
              "analyzer": "nlp_analyzer"
            },
            "standard_token_number": {
              "type": "token_count",
              "analyzer": "standard"
            }
          }
        },
        "original_tweet_created_at": {
          "type": "date"
        },
        "tweet_lang": {
          "type": "keyword"
        },
        "hashtags": {
          "type": "keyword"
        },
        "original_reply_to_pseudo": {
          "type": "keyword"
        },
        "original_reply_to_tweet": {
          "type": "keyword"
        },
        "original_reply_to_user_id": {
          "type": "keyword"
        },
        "reply_to_pseudo": {
          "type": "keyword"
        },
        "reply_to_tweet": {
          "type": "keyword"
        },
        "reply_to_user_id": {
          "type": "keyword"
        },
        "urls": {
          "type": "keyword"
        },
        "user_mentions_id": {
          "type": "keyword"
        },
        "user_mentions_pseudo": {
          "type": "keyword"
        },
        "inserted_in_es_at": {
          "type": "date"
        },
        "original_author_id": {
          "type": "keyword"
        },
        "author_id": {
          "type": "keyword"
        },
        "original_retweet_count": {
          "type": "integer"
        }
      }
    }
  }
}

Here is an example for adding records to Elasticsearch using Kibana Dev Tools:

{
        "_index": "twitter",
        "_type": "tweet",
        "_id": "907122919389745152",
        "_score": 1,
        "_routing": "1556482824",
        "_parent": "1556482824",
        "_source": {
          "tweet_id": "907122919389745152",
          "retweet_count": 0,
          "original_author_id": "367876848",
          "inserted_in_es_at": "2017-09-11T06:05:32.000Z",
          "tweet_created_at": "2017-09-11T06:05:32.000Z",
          "is_a_retweet": true,
          "user_mentions_id": [
            "367876848"
          ],
          "author_id": "1556482824",
          "original_tweet_id": "907121307296333824",
          "user_mentions_pseudo": [
            "rojanacabrera"
          ],
          "favorite_count": 0,
          "tweet_content": "Brytiago - Netflix Ft. Bad Bunny🎧",
          "original_tweet_created_at": "2017-09-11T05:59:07.000Z",
          "tweet_lang": "en",
          "original_retweet_count": 1,
          "sentiment": "positive"
        }
      }
 
 
 
{
  "_index": "twitter",
  "_type": "author",
  "_id": "1556482824",
  "_version": 1,
  "found": true,
  "_source": {
    "author_friends_count": 4398,
    "author_followers_count": 7433,
    "author_pseudo": "Bad_Bunny_Baby",
    "inserted_in_es_at": "2017-09-11T06:05:32.000Z",
    "author_id": "1556482824",
    "author_name": "Bad 🐰 Bunny",
    "author_account_creation": "2013-06-29T20:50:22.000Z",
    "is_author_verified": false,
    "author_lang": "es",
    "is_author_protected": false
  }
}

Even more examples:

PUT my_index
{ "settings" : {
   "index" : {
     "number_of_shards" : 1,
     "number_of_replicas" : 0
   },
   "analysis": {
     "analyzer": {
       "tweeter_analyser_nlp" :{
         "type" : "custom",
         "tokenizer" : "tweeter_tokenizer",
         "filter": ["lowercase"]
       }
     },
     "tokenizer": {
       "tweeter_tokenizer": {
         "type": "pattern",
         "pattern": "(\\w+)|(\\s*[\\s+])"
       }
     }
   }
 },
 "mappings": {
   "tweet": {
     "properties": {
       "text": {
         "type": "text",
         "term_vector": "yes",
         "analyzer" : "tweeter_analyser_nlp"
        },
        "fullname": {
         "type": "text",
         "term_vector": "with_positions_offsets_payloads",
         "analyzer" : "tweeter_analyser_nlp"
       }
     }
   }
 }
}

GET my_index/_analyze
{
 "analyzer": "tweeter_analyser_nlp",
 "text": "The twitter test!! :) @melvyn #test"
}

PUT my_index/tweet/0
{
 "fullname" : "Jane Doe",
 "text" : "The twitter test!!! :) @melvyn #test"
}

GET my_index/tweet/0/_termvectors
{
 "fields" : ["text"]
}

DELETE my_index

Create Index and Type for storing tweet data into Elasticsearch

PUT spanish_hashtag_tweets
{ "settings" : {
   "index" : {
     "number_of_shards" : 1,
     "number_of_replicas" : 0
   }
 },
 "mappings": {
   "type": {
     "properties": {
       "tweets": {
         "type": "text"
        }
     }
   }
 }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment