Elasticsearch's basic statement describes the aggregation function is very powerful to analyze the data

Source: Internet
Author: User
Tags elasticsearch aggregation

Elasticsearch aggregation is powerful and can analyze data more powerful than MySQL. Can be classified according to mountain climbing to sports ...
Here are the installation and some basic commands
Installation
Curl-l-O http://download.elasticsearch.org/PATH/TO/VERSION.zip <1>
Unzip elasticsearch- V E RS I ON .z IPCd eLasTICseaRCh? VERSION

Plug - ins
./bin/plugin-i Elasticsearch/marvel/latest

To disable monitoring, turn off 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",
"Lucene_version": "4.10"
},
"Tagline": "Know, for Search"
}
This means your elasticsearch cluster is up and running.

Database comparison
Database (relational DB), library (Databases), table (Tables), row (rows), column (Columns)
Elasticsearch, Index (Indices), type (Types), document (Documents), field (fields)

Create data
Put/megacorp/employee/1
{
"First_Name": "John",
"Last_Name": "Smith",
"Age": 25,
"About": "I love to go rock climbing",
"Interests": ["Sports", "music"]
}

Put/megacorp/employee/3
{
"First_Name": "Douglas",
"Last_Name": "Fir",
"Age": 35,
"About": "I like to build cabinets",
"Interests": ["forestry"]
}
Note that the path/MEGACORP/EMPLOYEE/1 contains three pieces of information:
Name
Description
Megacorp Index Name
Employee type name
1 ID of this employee

Search for all employees ' requests:
Get/megacorp/employee/_search
Query A
Get/megacorp/employee/_search?q=_id:au3leyatuy05zvit4rum

DSL statement Query JSON format
Get/megacorp/employee/_search
{
"Query": {
"Match": {
"Last_Name": "Smith"
}
}
}
Full-text fuzzy full-text search
Get/megacorp/employee/_search
{
"Query": {
"Match": {
"About": "Rock Climbing"
}
}
}
Inquire about the employees who contain the full phrase "rock climbing".
Get/megacorp/employee/_search
{
"Query": {
"Match_phrase": {
"About": "Rock Climbing"
}
}
}

Highlight Query Results
Get/megacorp/employee/_search
{
"Query": {
"Match_phrase": {
"About": "Rock Climbing"
}
},
"Highlight": {
"Fields": {
"About": {}
}
}
}

The Awesome aggregation function
Get/megacorp/employee/_search
{
"Aggs": {
"All_interests": {
"Terms": {"field": "Interests"}
}
}
}

Results
"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
}
]
}
}

Automatically classify employees ' hobbies like mountain climbing to sports!! Aggregation is the ability to analyze data

The most interesting hobby of the surname "Smith" is
Get/megacorp/employee/_search
{
"Query": {
"Match": {
"Last_Name": "Smith"
}
},
"Aggs": {
"All_interests": {
"Terms": {
"Field": "Interests"
}
}
}
}

To count the average age of employees under each type of interest
Get/megacorp/employee/_search
{
"Aggs": {
"All_interests": {
"Terms": {"field": "Interests"},
"Aggs": {
"Avg_age": {
"avg": {"field": "Age"}
}
}
}
}
}

Elasticsearch's basic statement describes the aggregation function is very powerful to analyze the data

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.