Wednesday, 10 March 2021

How to use curl to GET query / search in elasticsearch?

You can use curl commands to search/query in elasticsearch just like in Kibana.

For example: 

you can get the count the number of documents in the cluster, you can use  GET _count endpoint.

Using curl:

curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/_count?pretty' -d '

{

"query" : {

"match_all" : {}

}

}'


Without the header, you might get 406 Not Acceptable exception like 

{

  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",

  "status" : 406

}



Respective kibana command(short-hand):


GET _count

{

  "query": {

    "match_all": {}

  }

}


Monday, 8 March 2021

How to the check the elasticsearch cluster status using CURL command (whether it is UP & Running or not)?

 You can check the elasticsearch status by executing the following curl command: 

curl 'http://localhost:9200/?pretty'

generally, you must see the response something like the following text:


{

  "name" : "Dineshs.local",

  "cluster_name" : "elasticsearch",

  "cluster_uuid" : "cyHGu82bTNeWsmubNRblKA",

  "version" : {

    "number" : "7.9.3",

    "build_flavor" : "default",

    "build_type" : "tar",

    "build_hash" : "c4138e5121ef06a6404866cddc601906fe5c868",

    "build_date" : "2020-10-16T10:36:16.141335Z",

    "build_snapshot" : false,

    "lucene_version" : "8.6.2",

    "minimum_wire_compatibility_version" : "6.8.0",

    "minimum_index_compatibility_version" : "6.0.0-beta1"

  },

  "tagline" : "You Know, for Search"

}


This confirms that the Elasticsearch cluster is up and running

How to copy the files/directories into Kubernetes (K8S) Pods from local to remote pods (either ways)

Sometimes, we may get into situations where we need files from Kubernetes (K8S) pods to local file system & vice versa.

K8S has built-in commands for copying resources into & from K8S pods.

Case 1: To copy into local system from remote pods

kubectl cp <namespace_of_pod>/<pod_generated_name>:<source_copying_dir_path> <destination_local_dir_path>

kubectl cp catalog /catalog-app-es1xy2323sds:/appl/repositories     ~/

(here, I am copying the directory /appl/repositories from remote pod named catalog-app-es1xy2323sds (generated name) from Kubernetes cluster to local root path ~/ 

Case 2: To copy from local system to remote pods

kubectl cp <source_local_dir_path> <namespace_of_pod>/<pod_generated_name>:<destination_copying_dir_path> 

kubectl cp  ~/config  catalog /catalog-app-es1xy2323sds:/appl/repositories 

(here, I am copying the directory ~/config from local file system to remote pod named catalog-app-es1xy2323sds (generated name) in the namespace catalog)

you can search for all the namespaces using

kubectl get namespaces

you can search all the pods for a particular namespace using

kubectl get pods -n <namespace_name>

How to extract a TAR file in Linux / unix OS or on MAC

You can use tar command to extract, create, list, update, add/replace the files in the given .tar compressed file.

tar command provides the various options:

-t          List

-x         Extract

-c         Create

-r        Add/Replace


-v        Verbose

-f        <filename> Location of archieve


For Example, to list the contents/files in an given .tar file

tar -tf <.tar filename>            Lists all the files

tar -xvf <.tar filename>        Extracts all the files