API Convention | Elasticsearch API Convention - elasticsearch - elasticsearch tutorial - elastic search



Elasticsearch api convention

  • Application Programming Interface (API) in web is a gathering of capacity calls or other programming directions to get to the product segment in that specific web application.
  • For instance, Face book API encourages a designer to make applications by getting to information or different functionalities from Face book; it can be date of birth or announcement.
  • Elastic search gives a REST API, which is gotten to by JSON over HTTP. Elastic search utilizes the accompanying traditions
  • learn elasticsearch tutorials - api

    learn elasticsearch tutorials - api Example

Multiple Indices

  • Most of the operations, mainly searching and other operations, in APIs are for one or more than one indices.
  • This helps the user to search in multiple places or all the available data by just executing a query once.
  • Many different notations are used to perform operations in multiple indices.
  • We will discuss a few of them here in this section.
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node

Comma Separated Notation

POST http://localhost:9200/index1,index2,index3/_search
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Request Body

{
   "query":{
      "query_string":{
         "query":"any_string"
      }
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response

  • JSON objects from index1, index2, index3 having any string in it.

_all keyword for all indices

POST http://localhost:9200/_all/_search
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Request Body

{
   "query":{
      "query_string":{
         "query":"any_string"
      }
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response

  • JSON objects from all indices and having any string in it.

Wildcards ( * , + , - )

POST http://localhost:9200/school*/_search
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node

Request Body

{
   "query":{
      "query_string":{
         "query":"CBSE"
      }
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response

  • JSON objects from all indices which start with school having CBSE in it.
  • Alternatively, you can use the following code as well
POST http://localhost:9200/school*,-schools_gov /_search
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Request Body

{
   "query":{
      "query_string":{
         "query":"CBSE"
      }
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node

Response

  • JSON objects from all indices which start with “school” but not from schools_gov and having CBSE in it.
  • There are also some URL query string parameters
    • ignore unavailable − No error will occur or operation will not be stopped, if the one or more index present in URL does not exist.
  • For example, schools index exist but bookshops does not exist
POST http://localhost:9200/school*,book_shops/_search
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Request Body

{
   "query":{
      "query_string":{
         "query":"CBSE"
      }
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response

{
   "error":{
      "root_cause":[{
         "type":"index_not_found_exception", "reason":"no such index",
         "resource.type":"index_or_alias", "resource.id":"book_shops", 
         "index":"book_shops"
      }],
		
      "type":"index_not_found_exception", "reason":"no such index",
      "resource.type":"index_or_alias", "resource.id":"book_shops", 
      "index":"book_shops"
		
   },"status":404
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Take a look at the following code

POST http://localhost:9200/school*,book_shops/_search?ignore_unavailable = true
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Request Body

{
   "query":{
      "query_string":{
         "query":"CBSE"
      }
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response (no error)

  • JSON objects from all indices which start with school having CBSE in it.
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node

allow_no_indices

  • true value of this parameter will prevent error, if a URL with wildcard results in no indices.
  • For example, there is no index that starts with schools_pri
POST
http://localhost:9200/schools_pri*/_search?allow_no_indices = true
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Request Body

{
   "query":{
      "match_all":{}
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response (No errors)

{
   "took":1,"timed_out": false, "_shards":{"total":0, "successful":0, "failed":0}, 
   "hits":{"total":0, "max_score":0.0, "hits":[]}
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node

Expand _wildcards

  • This parameter decides whether the wildcards need to be expanded to open indices or closed indices or both. The value of this parameter can be open and closed or none and all.
  • For example, close index schools
POST http://localhost:9200/schools/_close
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response

{"acknowledged":true}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Take a look at the following code

POST http://localhost:9200/school*/_search?expand_wildcards = closed
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Request Body

{
   "query":{
      "match_all":{}
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response

Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Date Math Support in Index Names

  • Elastic search offers a functionality to search indices according to date and time. We need to specify date and time in a specific format.
  • For example, accountdetail-2015.12.30, index will store the bank account details of 30th December 2015.
  • Mathematic operations can be performed to get details for a particular date or a range of date and time.

Format for date math index name

<static_name{date_math_expr{date_format|time_zone}}>
http://localhost:9200/<accountdetail-{now-2d{YYYY.MM.dd|utc}}>/_search
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team
  • static name is a part of expression which remains same in every date math index like account detail.
  • Date math expr contains the mathematical expression that determines the date and time dynamically like now-2d. date format contains the format in which the date is written in index like YYYY.MM.dd.
  • If today’s date is 30th December 2015, then will return accountdetail-2015.12.28.
Expression Resolves to
<accountdetail-{now-d}> accountdetail-2015.12.29
<accountdetail-{now-M}> accountdetail-2015.11.30
<accountdetail-{now{YYYY.MM}}> accountdetail-2015.12
  • We will now see some of the common options available in Elasticsearch that can be used to get the response in a specified format.

Pretty Results

  • We can get response in a well-formatted JSON object by just appending a URL query parameter, i.e., pretty = true.
POST http://localhost:9200/schools/_search?pretty = true
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Request Body

{
   "query":{
      "match_all":{}
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response

{
   "_index" : "schools", "_type" : "school", "_id" : "1", "_score" : 1.0,
   "_source":{
      "name":"Central School", "description":"CBSE Affiliation", 
      "street":"Nagan", "city":"paprola", "state":"HP", "zip":"176115",
      "location": [31.8955385, 76.8380405], "fees":2000, 
      "tags":["Senior Secondary", "beautiful campus"], "rating":"3.5"
   }
}	
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Human Readable Output

  • This option can change the statistical responses either into human readable form (If human = true) or computer readable form (if human = false).
  • For example, if human = true then distance kilometer = 20KM and if human = false then distance meter = 20000, when response needs to be used by another computer program.
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node

Response Filtering

  • We can filter the response to less fields by adding them in the field path parameter. For example,
POST http://localhost:9200/schools/_search?filter_path = hits.total
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Request Body

{
   "query":{
      "match_all":{}
   }
}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

Response

{"hits":{"total":3}}
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - elasticsearch - elasticsearch tutorial - elastic - elastic search - elasticsearch docker team

 Elastic Search API Conventions

This tutorial provides some of the very important topics such as elasticsearch types , elasticsearch 5 , elasticsearch github , elasticsearch ui , elasticsearch wiki , elasticsearch indices , elasticsearch cluster , elasticsearch port , elasticsearch docs , elasticsearch configuration , elasticsearch terms , elasticsearch mapping , elasticsearch head , elasticsearch rest api , elasticsearch filter , elasticsearch search , elastic search query , elasticsearch database , elasticsearch marvel , elasticsearch gui , elasticsearch match , elasticsearch install , elasticsearch query example , elasticsearch api , elasticsearch update , kibana plugins , solr vs elasticsearch , logstash elasticsearch , elasticsearch kibana , elasticsearch vs solr , elasticsearch head plugin , elasticsearch logstash , elasticsearch aws , aws elastic search , elasticsearch php , elasticsearch example , elasticsearch logstash kibana , download elasticsearch , kibana demo , elasticsearch documentation , elasticsearch version , what is elasticsearch , elasticsearch plugin , elasticsearch log , elasticsearch download , elastic co

Related Searches to API Convention | Elasticsearch API Convention