Last active
December 15, 2015 22:09
-
-
Save stuart-warren/5331433 to your computer and use it in GitHub Desktop.
Examples of Elastic search commands to create indexes and input data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl -XDELETE 'http://localhost:9200/metrics' | |
| curl -XPUT 'http://localhost:9200/metrics/' -d ' | |
| { | |
| "settings" : { | |
| "index" : { | |
| "analysis" : { | |
| "analyzer" : { | |
| "metricanalyser" : { | |
| "type" : "custom", | |
| "tokenizer" : "pattern", | |
| "filter" : "lowercase" | |
| } | |
| }, | |
| "tokenizer" : { | |
| "yourcustomtokenizer" : { | |
| "type" : "standard", | |
| "max_token_length" : "900" | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ' | |
| curl -XPUT 'http://localhost:9200/metrics/metric/_mapping' -d ' | |
| { | |
| "metric" : { | |
| "properties" : { | |
| "name" : { | |
| "type" : "string", | |
| "search_analyzer" : "metricanalyser", | |
| "index_analyzer" : "metricanalyser" | |
| }, | |
| "time" : { | |
| "type" : "date", | |
| "format" : "dateOptionalTime" | |
| }, | |
| "value" : { | |
| "type" : "float" | |
| } | |
| } | |
| } | |
| } | |
| ' | |
| curl -s -XPUT 'http://localhost:9200/metrics/metric/_bulk' -d ' | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat1", "value" : "23.3" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat2", "value" : "20.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat3", "value" : "19.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat4", "value" : "232.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat5", "value" : "22.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat6", "value" : "23.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat7", "value" : "20.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat8", "value" : "4.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat9", "value" : "100.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.macbook.stat10", "value" : "2323.0" } | |
| ' | |
| curl -s -XPUT 'http://localhost:9200/metrics/metric/_bulk' -d ' | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.stata", "value" : "23.3" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.statb", "value" : "20.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.statc", "value" : "19.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.statd", "value" : "232.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.state", "value" : "22.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.statf", "value" : "23.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.statg", "value" : "20.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.stath", "value" : "4.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.stati", "value" : "100.0" } | |
| { "index" : { } } | |
| { "time" : "1365330850", "name" : "prd.server.statj", "value" : "2323.0" } | |
| ' | |
| curl -s -XPOST 'http://localhost:9200/metrics/metric/_search?pretty&sort=time' -d ' | |
| { | |
| "query" : { | |
| "term" : { "name" : "stat7" } | |
| } | |
| } | |
| ' | |
| curl -s -XPOST 'http://localhost:9200/metrics/metric/_search?pretty&sort=time' -d ' | |
| { | |
| "query" : { | |
| "query_string" : { | |
| "default_operator" : "AND", | |
| "default_field" : "name", | |
| "query" : "macbook.stat7" | |
| } | |
| } | |
| } | |
| ' | |
| curl -XGET 'localhost:9200/metrics/_analyze?field=metric.name' -d 'prd.macbook.stat7' | |
| ./randomdata.sh | curl -s -XPUT 'http://localhost:9200/metrics/metric/_bulk' --data-binary @- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "{ \"index\" : { } }" | |
| echo "{ \"time\" : \"`date +%s`\", \"name\" : \"prd.server.stata\", \"value\" : \"$RANDOM.3\" }" | |
| echo "{ \"index\" : { } }" | |
| echo "{ \"time\" : \"`date +%s`\", \"name\" : \"prd.server.statb\", \"value\" : \"$RANDOM.0\" }" | |
| echo "{ \"index\" : { } }" | |
| echo "{ \"time\" : \"`date +%s`\", \"name\" : \"prd.server.statc\", \"value\" : \"$RANDOM.0\" }" | |
| echo "{ \"index\" : { } }" | |
| echo "{ \"time\" : \"`date +%s`\", \"name\" : \"prd.server.statd\", \"value\" : \"$RANDOM.7\" }" | |
| echo "{ \"index\" : { } }" | |
| echo "{ \"time\" : \"`date +%s`\", \"name\" : \"prd.server.state\", \"value\" : \"$RANDOM.4\" }" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment