Top 10 ElasticSearch API Query for Developers

In this article, I will take you through 10 Best ElasticSearch API Query. Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capab...

In this article, I will take you through 10 Best ElasticSearch API Query. Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents. Elasticsearch is developed in Java. Here we will see different types of Elasticsearch api query one can use to check the snapshot and indices details.

Example 1: To setup the number of shards and replicas for your index

Ans. Below is the query to setup the number of shards and replicas.

curl -XPUT 'localhost:9200/index?pretty' -H 'Content-Type: application/json' -d '
{
"settings":{
           "number_of_shards":2,
           "number_of_replicas":1
           }
}
'

Example 2: To get all the snapshot in a nice output

Below is the query to get all the snapshot in a proper format.

curl -XGET "localhost:9200/_snapshot/testrepo/_all?pretty"

Example 3: To check the total number of snapshots 

Below is the query to check the total number of snapshots.

curl -XGET "localhost:9200/_snapshot/testrepo/_all?pretty" | grep -i snapshot | wc -l

Example 4: To check the total number of indices 

Below is the query to check the total number of indices.

curl -XGET "localhost:9200/_snapshot/testrepo/_all?pretty" | grep -i indices | wc -l

Example 5: To get only the indices from every snapshots

Below is the query to get only the indices from every snapshots

curl -XGET "localhost:9200/_snapshot/testrepo/_all?pretty" | jq -r '.snapshots[].indices'

Example 6: To get the 11th indices of every snapshots

Below is the query to get 11th indices of every snapshots

curl -XGET "http://192.168.13.16:9200/_snapshot/testrepo/_all?pretty" | jq -r '.snapshots[].indices[10]'

Example 7: To get only indices from first snapshot

Below is the query to get only indices from first snapshot.

curl -XGET "http://192.168.13.16:9200/_snapshot/testrepo/_all?pretty" | jq -r '.snapshots[0].indices[]'

Example 8: To get the first indice from every snapshot

Below is the query to get the first indice from every snapshot

curl -XGET "localhost:9200/_snapshot/testrepo/_all?pretty" | jq -r '.snapshots[].indices[0]'

Example 9: To get all indices from Second snapshot

Below is the query to get all indices from Second Snapshot.

curl -XGET "localhost:9200/_snapshot/testrepo/_all?pretty" | jq -r '.snapshots[1].indices[]'

Example 10: To get Second indices of every snapshots

Below is the query to get the second indices of every snapshots.

curl -XGET "localhost:9200/_snapshot/testrepo/_all?pretty" | jq -r '.snapshots[].indices[1]'


  • 发表于 2023-08-04 22:29
  • 阅读 ( 25 )

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
shitian
shitian

662 篇文章

作家榜 »

  1. shitian 662 文章
  2. 石天 437 文章
  3. 每天惠23 33 文章
  4. 小A 29 文章