- Resources
- Elasticsearch
- Elasticsearch trick sheet of the most important requests of Curl 252
Date pilot written by date
May 7, 2019
- Elasticsearch
- Plug -in do wordpress de elasticsearch fantásstico
- WordPress
Register
Do you have a database problem?Talk to a free expert
Home >>
Introduction
This article serves as a leaf of tricks and elasticsearch for some of the most useful curls requests necessary to execute HTTP requests in a curl cluster., including files, through several protocols using URL syntax.
Curl's name means "customer url."The Curl library command is simply:curling
miallCurl requests must be preceded by this command.The basic structure of the application header is only thecurling
Command followed by a URL.
Install CURL on your machine the server
- However, most Linux's latest versions come with Curl, CLL is quite easy to install if it has a previous Linux version.
- As in Ubuntu, you must use Debian's repository based on APT in a linux distribution based on Debian to install curl:
1 | sudoAPT update |
- In the districts of Red Hat Linux, such as Centos or Fedora, you can use Yum Package Manager to install the Curl Library:
1 | Yum installationcurling |
Curl heading structure:
- There are several application options that you can use in your request for elasticity.
curling
command and be preceded by a-
script. - If you are making these requests to a real server with an Internet domain, instead of ordering a premises, you must replace
Hostile
In the heading withhttps: // {your_domain}
Make sure to replace"{Your domain}"
with the domain name or server IP address.
Curl heading options:
-X
, So,-Solicity
- This application option indicates the HTTP verb used in the application.-HOH
, So,--header
- The heading option is critical, especially for any request that requires more heading information.-Silent
, So,-s
- The "Silent" option will not show errors.--verbose
, So,-V
- The detailed option will produce more information about the application.
Here is an example using the--verbose
o-V
Header option in a curl application made to an elasticsearch cluster:
Other heading options:
O
-X
The HTTP verb option can have a space after it, such as-X get
, or you can write without space, such as-Xget
o-Xput
.Although you can use unique quotes, which are really apostrops, in the header with the domain name, the command line in Windows does not support the unique apostrophs, in the heading of a curl application, like how
'Localhost: 9200/_bulk'
.You can use the
? Bonito
Option at the end of the heading to give the answer that Json returned a more friendly and readable aspect.
Some important warnings about the use of curl with elasticsearch
- Elasticsearch made some important rules changes to execute its HTTP requests from the versions 6.0 and 7.0.For example, mapping types have depreciated and now only one type of index data is allowed.
The depreciation of "type extraction" in elasticsearch 7.0:
A"Include_type_name"
The statement must now explicitly pass the header as a Boolean (for example"Incluir_type_name = false"
) For many Elasticsearch curl applications.This new rule applies to all HTTP requests from Elasticsearch, including requests made in the Kibana console.
Of version 7.0, thisInclude_type_name
The statement of the heading will be necessary when passing the type of document of an index together with the mapping body.
According to elastic documentation,Starting with elasticsearch version 8.x, the requestsNo more supportspecifying the types of documents and the integerInclude_type_name
The parameter will be completely eliminated, not only depreciates.However, take into account, in April 2019, there are stillSome insectsassociate withincluir_type_name = true
resource.
406 Type type error
From version 6.0, Elasticsearch made a change to require all Cll requests, with a content body, so that the type of content explicitly declares in the header.The lack of execution correctly of this request will result in a406
HTTP Status error.
You should simply include-H 'Type of content: app/json'
Somewhere in the application header to avoid this error.
Receive an error of type 406 header content after making a curl request for elasticsearch:
Watch the
Rice
Command for more information.
Use of curl applications to obtain elasticsearch_Set
Information:
- Pick it up
_set
state:
1 | curling-Xget "http: // localhost: 9200/_cluster/state? Pretty" |
- Get the health of the cluster:
1 | curling-XTO TAKE'Localhost: 9200/_Cluster/Health?Bonito '' |
DoingTO TAKE
RequestDes for Un ClUSTER ELASTICSEARCH using curl:
- O http
TO TAKE
The verb, according to the functionality of "Get", will not change the state of the elasticsearch cluster. - Elastic's Get API is used to obtain or "obtain" information about the cluster and its rates.
UsingTO TAKE
To return information about the elasticsearch cluster at a specific door:
1 | CURL Get-V 'Localhost: 9200' |
JSS's response must return the fields with the"Cluster_uuid
"E"Cluster_name"
information, assuming that elasticsearch is running in the standard port of9200
Ok that the door can be changed in theelasticsearch.yml
archive.
Get data in an index
You can use the following request to return the assignment of replicas, fragments and data and other information about this specific index in the cluster:
1 | curling-V -Xget 'Localhost: 9200/some_index?Incluir_type_name = false ' # ..o: CURL Get'Localhost: 9200/some_index?Bonito' ' # ..o: curling-VTO TAKE"https: // {domain_name}: 9200/algum_index? Pretty" |
You will notice that he-X
Option forcurling
The command is necessary tosomeCurl request.
Create an elasticsearch index using curl:
Here is a command that you can use to create an index with some configurations that specify the"Number_of_shards"
mi"Number_of_replicas"
For the index:
1 | curling-V -Xput "Localhost: 9200/some_index" -HOH 'ConteÚdo-Type: Application/JSON' -d ' |
Create an index"Cartography"
:
Here is a request that you can use to create an index usingPUT,
as well as a type of document in the heading (discontinued of version 6.0).
This request will also create a"Cartography"
Scheme for the index with text text, whole, Boolean and field dated:
1 | curling-V -Xput "Localhost: 9200/some_index/_mapping/doc_type? Pretty" -HOH 'ConteÚdo-Type: Application/JSON' -d ' |
Curl -v -xput "http: // localhost: 9200/any_index? Beautiful" -h 'content -type: application/json' -d '{"mapping": {
1
2
3
4
5
6
7
8
9
10
11"Some kind": {
"Properties": {
"Field_1": {"Type": "Text"},
"Field_2": {"type": "whole"},
"Field_3": {"tipo": "boolean"},
"Created": {
"Type": "date"
"Format": "epoch_second"
}
}
}
}} ‘``
OBSERVATION:With elasticsearch version 7.0 and more recent, mapping applications usingPUT
He will not accept the name of the type in the header.
You can also specify the"Cartography"
mi"Settings"
When an HTTP application is used to create an index.
Here is an example that shows how to create an index with fragments and replica"Settings."
This command will also give the index a"Cartography"
scheme:
1 | curling-V -Xput "Localhost: 9200/some_index? Incluir_type_name = false" -HOH 'ConteÚdo-Type: Application/JSON' -d ' |
You can use a curl application to returnallof the indices in an elasticsearch cluster:
If you are not sure of the indices you have created in a cluster, you can use this command to return a complete list of indexes, including hidden Kiban indices, as well as their respective UUID:
1 | curling-V -TO TAKELocalhost:9200/_gato/Indices?Pretty |
* Note that the index
Some_index,
previously created, it has a UUID ofQGDOYQFOKEQIGXVX2WKEUA
.
Delete data in an elastic research index
Be especially care when you make this type of applications, since it is very easy to accidentally delete indices, documents or data that I did not intend.
Eliminate an entire index in elasticsearch:
NOTICE: This action will exclude the entire index and should return a JSON response formatted with a"result"
Field that indicates that the application was successful:
1 | curling-V —Cee "Localhost: 9200/some_index? Bonito" |
You can also obtain the same results excluding the type of index document:
1 | curling—Cee "http: // localhost: 9200/some_index/_doc" |
Eliminate a document in an index:
1 | curling-V —Cee "Localhost: 9200/some_index/_doc/42" |
Using the_delete_by_query
API to eliminate documents:
O_delete_by_query
API can be used to segment and eliminate specific documents in an index.
NOTICE: The following request will excludeAllof your documents in the index:
1 | curling-Xpost 'Localhost: 9200/some_index/_doc/_delete_by_query?Bonito' -HOH 'ConteÚdo-Type: Application/JSON' -d ' |
CREACION AND INDEXACION OF Documents en Elasticsearch
You can also use CL requests with the index API to create, update and index documents. Similarly, pass the document data to the application agency, ensuring that data maps comply with the mapping described for the index.
UPDATE AND INDEXACION OF ELASTICSEARCH DOCUMENTS:
Here is an example of a simplePOST
Request that you can use to index a document.However, in this example, the identification document42
It has already been indexed, so this request will only update the document:
1 | # Generates a seal per hour in seconds from the moment # MAKE A PUN APPLICATION TO INDEXAR OR UPDATE, DOCUMENT # 42 |
OBSERVATION:If the index application fails and returns an error message with the"reason"
to beRejecting mapping update to [Sub_index] since the final allocation would have more than 1 type
It probably means that you passedIncorrect document typeIn the heading.com the versions of elasticsearch 7.0 or even, but not including, version 8.0, will probably have to pass_doc
as the type of document in the heading.
Making a groupPUT
Request that you return a JSON response from elasticsearch with a"result"
of"Updated"
:
As shown in the previous screen capture, you can use the
"+%S" dates
Eat at the terminal to generate a time of time of time, in seconds, and beaten it in the body of the curl application under the"created"
Campo.The types of entire data and Booleans can be transmitted
PUT
Json application body without quotes, such asFALSE,
instead of"FALSE."
Index an elasticity research document with a dynamically self -managed and created identification:
If the verb http changesPOST,
Instead of usingPUT,
and eliminate the explicit ID in the header after the type of document, create or index a document.
1 | # Use `post` instead of putting on 'and omit the ID: |
* In this example, the answer must have a
"result"
field with a value of"created."
In this case, Elasticsearch attributed an identification to the documentAubivgob8xrisdjrbkip
.
Using the_volume
API to index documents for elasticsearch:
You can use the_volume
option at the end of the heading and include a JSON object with the"I went"
declared for each document in a"index"
Campo:
1 | curling-V -Xpost "http: // localhost: 9200/some_index/_doc/_bulk? Pretty" -HOH 'ConteÚdo-Type: Application/JSON' -d ' |
- Make sure there is a return space between each document, do not eat, since the new line character is what acts as a delimitator.
Press a full JSON file of elasticsearch documents using curl:
The JSON file must follow a JSON format similar to the previous_volume
API example.You can specify the"_index"
name is_type"
before each document.
This example neglects to declare IDS so that elasticsearch can dynamically generate alpha-nummer for each document:
1 | {"index":{"_index":"Some_index", So,"_type":"_doc"}} |
Simply enter this data into a text editor and save the file asdata.json
.cd
In the same directory of the file and then make the request to load the JSON file in its elasticsearch cluster:
1 | curling-V -Xput 'http: // localhost: 9200/some_index/_doc/_bulk?Bonito' ' -HOH 'ConteÚdo-Type: Application/JSON' -Scasas @data.json |
Elasticsearch"Consultation"
Applications using the research API:
You can use the_look for
Heading option to execute consultations for consultation that will befairReturn certain documents that correspond to specific criteria.
basic"consultation"
Order:
- All
"consultation"
Applications will have one or more fields used as search parameters.Here is an example of a simple query used to match all the documents containing the chain"Forty-two
":1
2
3
4
5
6
7
8
9curling-XTO TAKE"Localhost: 9200/_Search? Pretty" -HOH 'ConteÚdo-Type: Application/JSON' -d'
{
"consultation": {
"correspond": {
"_All": "forty -dos"
}
}
}
'
Use the_fuente
Option to limit the fields returned by the consultation:
1 | curling-XTO TAKE"Localhost: 9200/People1/_Search? Pretty" -HOH 'ConteÚdo-Type: Application/JSON' -d ' |
OBSERVATION:It is essential not to forget to add the supports "[]" no "_fuente"
field every time you consult the field and value, or you will receive ajava.lang.illegalargumentException
error.
You can consult people who fall in certain age groups using these commands:Gte = greater than or equal to;lte = less than or equal to:
1 | curling-XTO TAKE"Localhost: 9200/Pessoas/_Search? Pretty" -HOH 'ConteÚdo-Type: Application/JSON' -d ' |
Here is an example of a consultation request that indicates that a particular field must correspond:
1 | curling-XTO TAKE"Localhost: 9200/People1/_Search? Pretty" -HOH 'ConteÚdo-Type: Application/JSON' -d ' |
Conclusion
In this tutorial, he has learned to execute several of the most used commands to make HTTP requests in a curl elasticsearch cluster.Most Linux's latest versions come with the curl prior to grades.Have
When using this trick sheet, remember that different versions of Elasticsearch will have some command line requirements.The incorrect type of document in the header and406
STATE ERROR HTTP TYPE.
To evaluate
Give back
Pilot of the Objectcket platform for free!
Try cheap totally managed, elasticsearch, Mongodb, Postgresql (beta) or redis.