Elasticsearch Curl Operation

Source: Internet
Author: User
Tags curl
Operation of Curl
Curl is an open source file Transfer tool that works with URL syntax in the command line mode, and using curl makes it easy to implement common get/post requests. Simply think of a tool that can access the URL below the command line. In the CentOS default library there are curl tools, if not please install Yum.
Curl
-x Specifies HTTP request method with head GET POST PUT DELETE
-d Specifies the data to transfer
-h Specifies HTTP request header information
Browse ES servers
Curl-xget http://master:9200 <=> Access in the browser
Create an index library
Curl-xput http://master:9200/bigdata_p
This creates an index library in es bigdata_p

Both post and put can be used to create the difference between the two:
Put is a idempotent method, and post is not. So put user update, post for new more appropriate.
Es points of note when creating index libraries and indexes
1) The index library name must be all lowercase, cannot begin with an underscore, and cannot contain commas
2) If the ID of the index data is not explicitly specified, then ES will automatically generate a random ID, which requires the use of the post parameter
Curl-xpost http://localhost:9200/bigdata/product/-d ' {"Author": "Doug Cutting"} '
Add data to the index library
In the specific type, add the relevant document
Curl-xput http://master:9200/bigdata_p/product/-d ' {"name": "Hadoop", "Author": "Doug cutting", "c_version": "2.7.3"} '
Querying data in an index library
Querying the entire index library: Curl-xget Http://master:9200/bigdata_p/_search?pretty
Adding a pretty after the URL will format the returned result.
Query a type:curl-xget http://master:9200/bigdata_p/product/_search?pretty
Query for a specific record: Curl-xget Http://master:9200/bigdata_p/product/1?pretty
Query for a specific field in an indexed document: Curl-xget Http://master:9200/bigdata_p/product/1?_source=name&pretty
If you want to query multiple fields, use "," to separate them. eg.
Curl-xget Http://master:9200/bigdata_p/product/1?_source=name,author&pretty
Get Source All data
Curl-xget Http://master:9200/bigdata_p/product/1?_source&pretty
Query based on criteria
Curl-xget Http://master:9200/bigdata_p/product/_search?q=name:hbase,hive&pretty
-------------------
ES update
ES can use put or post to update a document, and if a document with the specified ID already exists, the update operation is performed
Note: When performing an update, ES first marks the old document as deleted, and then adds a new document, the old
The file will not disappear immediately, but you cannot access it, and ES will continue to add more data when the background cleanup has been marked as deleted.
Document except the state.
Local updates
You can add a new field or update a field that already exists (you must use post)
Curl-xpost http://master:9200/bigdata_p/product/2/_update-d ' {"Doc": {"c_version": "2.0.0", "Publish_time": " 2017-03-23 "}} '
Query Result:
"Hits": [{
"_index": "Bigdata_p",
"_type": "Product",
"_id": "2",
"_score": 0.30685282,
"_source": {
"Name": "HBase",
"Author": "Apache",
"C_version": "2.0.0",
"Publish_time": "2017-03-23"
}
} ]
Normal Delete, delete according to primary key
Curl-xdelete http://master:9200/bigdata_p/product/3/
Description: If the document exists, the ES property of the Found:true,successful:1,_version property has the value +1.
If the document does not exist, the ES property found is false, but the version value, versions, is still +1, which is the internal
Management, a bit like the SVN version number, guarantees that the order of our different operations across multiple nodes is correctly marked.
Note: After a document is deleted, it does not take effect immediately and he is only marked as deleted. ES will be added after you
More indexes will be deleted in the background.

Bulk Operation-bulk
Bulk API can help us execute multiple requests at the same time
Format:
Action:[index|create|update|delete]
metadata:_index,_type,_id
Request Body:_source (delete operation not required)
{action:{metadata}}\n
{Request body}\n
{action:{metadata}}\n
{Request body}\n
The difference between create and index
If the data exists, using the create operation fails, prompting the document to already exist, and using index to execute successfully.

How files are used
Curl-xpost/put Http://master:9200/index/type/_bulk--data-binary @path
Like what
Curl-xpost ' Http://master:9200/bank/account/_bulk--data-binary @/home/uplooking/documents/accounts.json
Query Result:
Http://master:9200/bank/_search?pretty
{
"Took":----> Default Top 10
"Timed_out": false,
"_shards": {
"Total": 5,
"Successful": 5,
"Failed": 0
},
"Hits": {
"Total":-----> 1000 Records
"Max_score": 1.0,
Can look at the individual index library information
Curl ' http://localhost:9200/_cat/indices?v '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.