Skip to content

Instantly share code, notes, and snippets.

@syberkitten
Created December 4, 2014 14:18
Show Gist options
  • Save syberkitten/f3c961d64896106e2a2b to your computer and use it in GitHub Desktop.
Save syberkitten/f3c961d64896106e2a2b to your computer and use it in GitHub Desktop.
ElasticSearch basic Curl API calls
get specific document:
curl -XGET 'http://localhost:9200/php_logging/flv_pl/1'
get specific document:
curl -XGET 'http://localhost:9200/php_logging/flv_pl'
get documents:
curl http://localhost:9200/php_logging/_search?pretty=true&q=*:*
flush index:
curl -XPOST 'http://localhost:9200/php_logging/_flush'
delete index:
curl -XDELETE 'http://localhost:9200/php_logging'
list indexes:
curl 'localhost:9200/_cat/indices?v'
see mapping for index:
curl -XGET 'http://127.0.0.1:9200/php_logging/_mapping?pretty=1'
create timstamp on index:
--------------------------------------------
curl -XPOST localhost:9200/php_logging -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"_default_":{
"_timestamp" : {
"enabled" : true,
"path":"datetime"
},
"dynamic_date_formats" : ["date_time"]
}
}
}'
DELETE INDEX / CREATE / INSERT DOCUEMTS / QUERY
------------------------------------
curl -XDELETE 'http://localhost:9200/php_logging'
curl -XPOST localhost:9200/php_logging -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"_default_":{
"_timestamp" : {
"enabled" : true,
"path":"datetime"
}
}
}
}'
curl -XPUT 'http://localhost:9200/php_logging/flv_pl/1' -d '{
"@version": "0.1.1",
"user" : "test_user",
"message" : "66666666+1",
"datetime":"2014-12-04T11:23:02.133Z"
}'
curl -XPUT 'http://localhost:9200/php_logging/flv_pl/2' -d '{
"@version": "0.1.1",
"user" : "test_user",
"message" : "66666666+2",
"datetime":"2014-12-04T11:24:02.133Z"
}'
curl -XGET 'http://127.0.0.1:9200/php_logging/_mapping?pretty=1'
-----------------------------------------
PLAYGROUND:
create index with json parsing:
--------------------------------------------
curl -XDELETE 'http://localhost:9200/testing'
curl -XPOST localhost:9200/testing -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"_default_":{
"properties": {
"message" : {
"type" : "object"
}
},
"dynamic_date_formats" : ["date_time"]
},
"test":{
"message" : {
"type" : "object"
}
}
}
}'
curl -XGET 'http://127.0.0.1:9200/testing/_mapping?pretty=1'
curl -XPUT 'http://localhost:9200/testing/test/2' -d '{
"user" : "test_user1",
"message" : {"url":"http://www.walla.co.il","myage":30},
"datetime":"2014-12-04T11:24:02.133Z"
}'
curl -XGET 'http://127.0.0.1:9200/testing/_mapping?pretty=1'
-------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment