Elasticsearh - usign REST interface

in these examples we use curl but you can use wget, PUT, GET, DELETE where supported

Check we can connect to the cluster


In [ ]:
# define our address so we dont have to type it all the time
address='atlas-kibana.mwt2.org:9200'

! curl "$address/_cluster/health"

Index one document we have in a json file


In [ ]:
! curl -XPOST "$address/my_events/event"  -d @OneDoc.json

BULK Index the documents we have in a json file


In [ ]:
! curl -XPOST "$address/my_events/_bulk" --data-binary "@ExampleDocs.json"

Get information on what and index settings and docs we have in it


In [ ]:
! curl -XGET "$address/my_events/_settings"

# number of documents
! curl -XGET "$address/my_events/event/_count"

Check that the data has been correctly mapped


In [ ]:
! curl -XGET "$address/my_events/_mappings"

Delete newly created index


In [ ]:
!curl -XDELETE "$address/my_events"

create a template for our data


In [ ]:
! curl -XPOST "$address/_template/my_events" -d @ExampleTemplate.json

index the data again


In [ ]:
! curl -XPOST "$address/my_events/_bulk" --data-binary "@ExampleDocs.json"

Check mapping now


In [ ]:
! curl -XGET "$address/my_events/_mappings"

Search for a document


In [ ]:
! curl -XGET "$address/my_events/event/_search?pretty&q=eventnr:>1"

In [ ]:
q= '{  \\"aggs\\" : {   \\"events_stats\\" : { \\"stats\\" : { \\"field\\" : \\"eventnr\\" } }  } }'
! curl -XGET "$address/my_events/event/_search?pretty"  -H 'Content-Type: application/json'   -d"$q"

Clean up


In [ ]:
!curl -XDELETE "$address/my_events"