Introduction to basic statements of elasticsearch the aggregation function is powerful for analyzing data.

Source: Internet
Author: User

Introduction to basic statements of elasticsearch the aggregation function is powerful for analyzing data.

Elasticsearch has powerful aggregation functions to analyze data, which is more powerful than MySQL. It can be categorized into sports based on mountain climbing...
Below are the installation and some basic commands
Install
Curl-L-O http://download.elasticsearch.org/PATH/TO/VERSION.zip <1>
Unzip elasticsearch- VERSION.zip cdelasticsearch − VERSION

Plug-ins
./Bin/plugin-I elasticsearch/marvel/latest

Disable monitoring and disable Marvel:
Echo 'Marvel. agent. enabled: false'>./config/elasticsearch. yml

Run
Cd/usr/share/elasticsearch
./Bin/elasticsearch

Open another terminal to run the test:
Curl: 'http: // localhost: 9200 /? Pretty'
You can see the following information :{
"Status": 200,
"Name": "Shrunken Bones ",
"Version ":{
"Number": "1.4.0 ",
"E_e_version": "4.10"
},
"Tagline": "You Know, for Search"
}
This indicates that your ELasticsearch cluster has been started and runs.

Database comparison
Relational Databases-> Tables-> Rows-> Columns)
Elasticsearch-> index (Indices)-> type (Types)-> document (Documents)-> Field (Fields)

Create data
PUT/employee Corp/employee/1
{
"First_name": "John ",
"Last_name": "Smith ",
"Age": 25,
"About": "I love to go rock climbing ",
"Interests": ["sports", "music"]
}

PUT/employee Corp/employee/3
{
"First_name": "Douglas ",
"Last_name": "Fir ",
"Age": 35,
"About": "I like to build cabinets ",
"Interests": ["forestry"]
}
Note that path/employee Corp/employee/1 contains three parts:
Name
Description
Megacorp index name
Employee type name
1. employee ID

Request for searching all employees:
GET/shortcorp/employee/_ search
Query one
GET/shortcorp/employee/_ search? Q = _ id: AU3leyatuy05ZviT4RuM

DSL statement query json format
GET/shortcorp/employee/_ search
{
"Query ":{
"Match ":{
"Last_name": "Smith"
}
}
}
Full-text fuzzy full-text search
GET/shortcorp/employee/_ search
{
"Query ":{
"Match ":{
"About": "rock climbing"
}
}
}
Query the employees whose about contains the complete phrase "rock climbing.
GET/shortcorp/employee/_ search
{
"Query ":{
"Match_phrase ":{
"About": "rock climbing"
}
}
}

Highlight query results
GET/shortcorp/employee/_ search
{
"Query ":{
"Match_phrase ":{
"About": "rock climbing"
}
},
"Highlight ":{
"Fields ":{
"About ":{}
}
}
}

Awesome Aggregation Function
GET/shortcorp/employee/_ search
{
"Aggs ":{
"All_interests ":{
"Terms": {"field": "interests "}
}
}
}

Result
"Aggregations ":{
"All_interests ":{
"Doc_count_error_upper_bound": 0,
"Sum_other_doc_count": 0,
"Buckets ":[
{
"Key": "music ",
"Doc_count": 4
},
{
"Key": "sports ",
"Doc_count": 4
},
{
"Key": "forestry ",
"Doc_count": 3
}
]
}
}

Employees are automatically classified as hobbies, such as hiking and sports !! The aggregation function is used to analyze data.

Which of the following interests is Smith?
GET/shortcorp/employee/_ search
{
"Query ":{
"Match ":{
"Last_name": "smith"
}
},
"Aggs ":{
"All_interests ":{
"Terms ":{
"Field": "interests"
}
}
}
}

Average age of employees under each interest
GET/shortcorp/employee/_ search
{
"Aggs ":{
"All_interests ":{
"Terms": {"field": "interests "},
"Aggs ":{
"Avg_age ":{
"Avg": {"field": "age "}
}
}
}
}
}

Related Article

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.