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 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
Request Body
Response
- JSON objects from index1, index2, index3 having any string in it.
_all keyword for all indices
Request Body
Response
- JSON objects from all indices and having any string in it.
Wildcards ( * , + , - )
elasticsearch - elasticsearch tutorial - elastic search - elasticsearch sort - elasticsearch list indexes - elasticsearch node
Request Body
Response
- JSON objects from all indices which start with school having CBSE in it.
- Alternatively, you can use the following code as well
Request Body
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
Request Body
Response
Take a look at the following code
Request Body
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
Request Body
Response (No errors)
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
Response
Take a look at the following code
Request Body
Response
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 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.
Request Body
Response
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,