Skip to content

Instantly share code, notes, and snippets.

@jworl
jworl / yaml2json.sh
Created June 29, 2017 14:54
yaml2json function within bash
# requires PyYAML
_YAML2JSON(){
python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < $1
}
@jworl
jworl / es_index_property.sh
Created August 31, 2017 18:45
display elasticsearch index properties
index=$1
curl -XGET 'http://localhost:9200/${index}?pretty'
@jworl
jworl / es_delete_index.sh
Created September 1, 2017 21:46
Delete elasticsearch index
INDEX=$1
curl -XDELETE http://localhost:9200/${INDEX}
TEMPLATE=$1
curl -XGET 'localhost:9200/_template/${TEMPLATE}?pretty'
@jworl
jworl / es_delete_by_query.sh
Last active September 7, 2017 19:13
elasticsearch delete by query
ES_DELETE_QUERY(){
INDEX=$1
KEY=$2
VALUE=$3
curl -XPOST 'localhost:9200/${INDEX}/_delete_by_query?scroll_size=5000&pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"match": {
"${KEY}": "${VALUE}"
}
@jworl
jworl / logstash_template.sh
Last active September 14, 2017 15:15
elasticsearch template used by logstash for output
# Create logstash template for pipeline
LOGSTASH_TEMPLATE() {
pipeline=$1
curl -XPUT http://localhost:9200/_template/${pipeline}?pretty -H 'Content-Type: application/json' -d'
{
"order" : 0,
"version" : 50002,
"template" : "${pipeline}-*",
"settings" : {
"index" : {
@jworl
jworl / es_template_pfsense.sh
Last active September 14, 2017 16:06
create elasticsearch template used for pfsense logstash output
curl -XPUT http://localhost:9200/_template/pfsense?pretty -H 'Content-Type: application/json' -d'
{
"order" : 0,
"version" : 50002,
"template" : "pfsense-*",
"settings" : {
"index" : {
"number_of_shards": 3,
"number_of_replicas": 1,
"refresh_interval" : "30s"
@jworl
jworl / es_indices.sh
Created August 31, 2017 18:46
show all elasticsearch indices with stats
curl -XGET 'localhost:9200/_cat/indices?v&pretty'
# set the following cluster settings to prevent rebalancing
curl -XPUT 'localhost:9200/_cluster/settings?pretty' -H 'Content-Type: application/json' -d'
{
"persistent": {
"cluster.routing.allocation.enable": "none"
}
}
'
@jworl
jworl / cluster_rebalance.sh
Created January 8, 2018 01:54
global settings for cluster rebalance
curl -XGET 'localhost:9200/_cluster/settings?pretty'
{
"persistent" : {
"cluster" : {
"routing" : {
"allocation" : {
"enable" : "all"
}
}
}