ElasticSearch(1)Installation and Simple Use
1. Introduction and Installation
Elasticsearch is based on Apache lucene. ES provide RESTful API.
Download the last one from here http://www.elasticsearch.org/download/
I download the version 1.4.0 this time. https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.0.tar.gz
Unzip the file and place it in the working directory.
Start the Server
>bin/elasticsearch
Visit this URL
http://localhost:9200/?pretty
{
"status" : 200,
"name" : "Mar-Vell",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "1.4.0",
"build_hash" : "bc94bd81298f81c656893ab1ddddd30a99356066",
"build_timestamp" : "2014-11-05T14:26:12Z",
"build_snapshot" : false,
"lucene_version" : "4.10.2"
},
"tagline" : "You Know, for Search"
}
We install and start the server successfully.
2. API
Java API
Node Client: The Node client will join the cluster. The system does not have any data in Node Client. But Node Client know where is the data.
Transport Client: It will not join the cluster, but it will send the request to the cluster.
http://www.elasticsearch.org/guide/
It seems that we have Java, JavaScript, Groovy, PHP, Perl, Python, Ruby API.
HTTP RESTful API
use CURL to check how many files we have
>curl -XGET 'http://localhost:9200/_count?pretty' -d '
> { > "query":{ > "match_all":{} > } > } > ' { "count" : 0, "_shards" : { "total" : 0, "successful" : 0, "failed" : 0 } }
-i will ask curl to response the header information
>curl -i -XGET 'localhost:9200/'
HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 Content-Length: 336
…snip…
3. Document Oriented
JSON, ES(elastic search) will store and index the JSON data.
4. Build Index
Create a Employee List
Normal Database ——> Database ——> Table ——> Row ——> Columns
Elasticsearch ———> Index ——>Type ——>Doc ——> Fields
create the index
>curl -XPUT 'http://localhost:9200/megacorp/employee/1' -d '
> { > "first_name" : "Carl", > "last_name" : "Luo", > "age": 33, > "about": " I love java, python, scala, groovy", > "interests": [ "sports", "music"] > } > ' {"_index":"megacorp","_type":"employee","_id":"1","_version":1,"created":true}
megacorp is the index name, something like database
employee is the type name, something like the table
1 is the id of the doc.
Create some Other Data
>curl -XPUT 'http://localhost:9200/megacorp/employee/1' -d '
> {> "first_name" : "Carl",> "last_name" : "Luo",> "age": 33,> "about": " I love java, python, scala, groovy",> "interests": [ "sports", "music"]> }> '
>curl -XPUT 'http://localhost:9200/megacorp/employee/3' -d '
> { > "first_name" : "Douglas", > "last_name" : "Fir", > "age" : 35, > "about" : "I like to build cabinets", > "interests" : [ "forestry" ] > } > '
5. Search the Doc
Something like key value, if we plan to fetch some data, just do like this.
>curl -XGET 'http://localhost:9200/megacorp/employee/1'
{"_index":"megacorp","_type":"employee","_id":"1","_version":1,"found":true,"_source": { "first_name" : "Carl", "last_name" : "Luo", "age": 33, "about": " I love java, python, scala, groovy", "interests": [ "sports", "music"] }
GET, DELETE
Something Useful for Search
List all the employee
>curl -XGET 'http://localhost:9200/megacorp/employee/_search'
Query String for Search
>curl -XGET 'http://localhost:9200/megacorp/employee/_search?q=last_name:Smith'
{"took":25,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.30685282,"hits":[{"_index":"megacorp","_type":"employee","_id":"2","_score":0.30685282,"_source": { "first_name" : "Jane", "last_name" : "Smith", "age" : 32, "about" : " I like to collect rock albums", "interests" : [ "music" ] }
_search?q=last_name:Smith
Using Query DSL
Domain Specific Language, JSON
>curl -XGET 'http://localhost:9200/megacorp/employee/_search' -d '
{ "query" : { "match" : { "last_name" : "Smith" } } }'
Try Complex Query
curl -XGET 'http://localhost:9200/megacorp/employee/_search' -d ' > { > "query" : { > "filtered" : { > "filter" : { > "range": { > "age" : { "gt" : 30 } > } > }, > "query" : { > "match" : { > "last_name" : "Smith" > } > } > } > } > } > '
Add Filter for the age > 30. gt is short for Greater Than.
6. Search the Full Document
{
“query” : {
“match” : {
“about” : “rock climbing"
}
}
}
It will return the about column contains “rock”, “climbing”, “rock climbing"
{
“query” : {
“match_phrase” : {
“about” : “rock climbing"
}
}
}
match phrase will only return the “rock climbing”
High Light the Search Result
>curl -XGET 'http://localhost:9200/megacorp/employee/_search' -d '
{ > "query":{ > "match_phrase":{ > "about" : "rock albums" > } > }, > "highlight":{ > "fields":{ > "about":{} > } > } > } > ' {"took":26,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.23013961,"hits":[{"_index":"megacorp","_type":"employee","_id":"2","_score":0.23013961,"_source": { "first_name" : "Jane", "last_name" : "Smith", "age" : 32, "about" : " I like to collect rock albums", "interests" : [ "music" ] } ,"highlight":{"about":[" I like to collect <em>rock</em> <em>albums</em>"]}}]}}
7. Aggregations
curl -XGET 'http://localhost:9200/megacorp/employee/_search' -d ' { "aggs":{ "all_interests":{ "terms": { "field" : "interests" } } } } '
http://fuxiaopang.gitbooks.io/learnelasticsearch/content/getting_started/tutorial_aggregations.html
References:
http://www.elasticsearch.org/overview/
http://fuxiaopang.gitbooks.io/learnelasticsearch/content/
http://www.oschina.net/translate/elasticsearch-getting-started
http://liuhongjiang.github.io/tech/blog/2013/01/11/es/
http://nkcoder.github.io/blog/20140217/elasticsearch-install-config/
相关推荐
Elasticsearch 8.14.1 是一个高度可扩展的开源全文检索和分析引擎,专为分布式环境设计。它允许开发者和系统管理员快速、高效地存储、搜索和分析大量数据。Elasticsearch 广泛应用于日志分析、信息检索、网站搜索、...
Get to grips with the basics of Elasticsearch concepts and its APIs, and use them to create efficient applications Create large-scale Elasticsearch clusters and perform analytics using aggregation A ...
Installation and the Requirements for Elasticsearch Chapter 3. Elasticsearch-head and Bigdesk Chapter 4. Marvel Dashboard Chapter 5. System Monitoring Chapter 6. Troubleshooting Performance and ...
Elasticsearch(简称ES)是一款强大的开源搜索引擎,广泛应用于数据检索、分析和管理。作为分布式、RESTful风格的搜索和数据分析引擎,Elasticsearch能够提供实时、高可用性以及可扩展的搜索功能。在进行日常的数据...
You'll start with the very basics: Elasticsearch terminology, installation, and configuring Elasticsearch. After this, you'll take a look at analytics and indexing, search, and querying. You'll learn ...
(狂神)ElasticSearch快速入门笔记,ElasticSearch基本操作以及爬虫(Java-ES仿京东实战),包含了小狂神讲的东西,特别适合新手学习,笔记保存下来可以多看看。好记性不如烂笔头哦~,ElasticSearch,简称es,es是一个...
根据提供的文件信息,我们可以推断出本篇文章将围绕Elasticsearch 6.2.2版本进行详细介绍,包括其下载方式、主要功能特性以及在实际应用中的常见用途。 ### Elasticsearch简介 Elasticsearch是一款基于Lucene的...
1.保存和存储几个Elasticsearch端点 2.索引选项卡中的更多列 3. 任何请求现在都可以像 /_cat/indices 一样处理 JSON 返回 4. 更简约的外观(更小的字体等...) Multi-Elasticsearch-Head是一个用于管理多个Elastic...
在数据抽取 ELT 领域,ES 全家桶 ELK(Elasticsearch+Logstash+Kibana)赫赫有名。 Elasticsearch 基本概念: * 倒排索引:Elasticsearch 为什么快,核心设计理念就是采用了倒排索引机制。倒排索引的方式是,根据 ...
By the end of the book, you will have all the knowledge necessary to master Elasticsearch and put it to efficient use. What you will learn Understand Apache Lucene and the Elasticsearch 5.0 design ...
1. **下载与解压**: 首先,你需要从官方网站下载适用于Windows的Elasticsearch 8.11.3版本,即`elasticsearch-8.11.3-windows-x86_64.zip`。解压缩后,将文件夹放置在合适的目录下。 2. **环境变量设置**: 将...
Elasticsearch 是位于 Elastic Stack 核心的分布式搜索和分析引擎。Logstash 和 Beats 有助于收集、聚合和丰富您的数据并将其存储在 Elasticsearch 中。Kibana 使您能够以交互方式探索、可视化和分享对数据的见解,...
Elasticsearch(ES)是一种流行的开源全文搜索引擎,它基于Lucene构建,提供了分布式、RESTful风格的搜索和分析引擎服务。在中文环境下,为了实现精确的分词和搜索,我们需要安装适合版本的分词插件,如“elastic...
适用于7.17.1系列,例如Elasticsearch的7.17.12版本。 elasticsearch-analysis-ik 是一个常用的中文分词器,在 Elasticsearch 中广泛应用于中文文本的分析和搜索。下面是 elasticsearch-analysis-ik 分词器的几个...
es-head是一个针对Elasticsearch的可视化操作插件。它提供了一个便捷的操作工具,可以连接Elasticsearch搜索引擎,并提供可视化的操作页面,对Elasticsearch进行各种设置和数据检索功能的管理。 es-head 插件可以在...
`start` 用于启动Elasticsearch,这里使用 `su` 命令切换到指定的Elasticsearch用户(例如 `es-admin`),然后进入Elasticsearch的安装目录并执行 `bin/elasticsearch` 文件以后台模式启动服务。`stop` 通过查找并杀...