1.1.  ElasticSearch(简称ES)

ES即为了解决原生Lucene使用的不足,优化Lucene的调用方式,并实现了高可用的分布式集群的搜索方案,其第一个版本于2010年2月出现在GitHub上并迅速成为最受欢迎的项目之一。

ES的核心不在于Lucene,其特点更多的体现为:

分布式的实时文件存储,每个字段都被索引并可被搜索

分布式的实时分析搜索引擎

可以扩展到上百台服务器,处理PB级结构化或非结构化数据

高度集成化的服务,你的应用可以通过简单的 RESTful API、各种语言的客户端甚至命令行与之

交互。

上手Elasticsearch非常容易。它提供了许多合理的缺省值,并对初学者隐藏了复杂的搜索引擎理论。它拥有开瓶即饮的效果(安装即可使用),只需很少的学习既可在生产环境中使用。

和ES类似的框架

Solr

Solr和ES比较:

Solr 利用 Zookeeper 进行分布式管理,支持更多格式的数据(HTML/PDF/CSV),官方提供的功能更多在传统的搜索应用中表现好于 ES,但实时搜索效率低。

ES自身带有分布式协调管理功能,但仅支持json文件格式,本身更注重于核心功能,高级功能多有第三方插件提供,在处理实时搜索应用时效率明显高于 Solr。

Katta

基于 Lucene 的,支持分布式,可扩展,具有容错功能,准实时的搜索方案。

优点:开箱即用,可以与 Hadoop 配合实现分布式。具备扩展和容错机制。

缺点:只是搜索方案,建索引部分还是需要自己实现。在搜索功能上,只实现了最基本的需求。成功案例较少,项目的成熟度稍微差一些。

HadoopContrib

Map/Reduce 模式的,分布式建索引方案,可以跟 Katta 配合使用。

优点:分布式建索引,具备可扩展性。

缺点:只是建索引方案,不包括搜索实现。工作在批处理模式,对实时搜索的支持不佳。

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman",serif;}

ES数据管理

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman",serif;}

创建索引文档

①使用自己的ID创建:

PUT {index}/{type}/{id}

{

"field": "value",

...

}

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman",serif;}

局部更新文档

接受一个局部文档参数 doc,它会合并到现有文档中,对象合并在一起,存在的标量字段被覆盖,新字段被添加。

POST itsource/employee/123/_update

{

“doc”:{

"email" : "nixianhua@itsource.cn",

"salary": 1000

}

}

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman",serif;}

删除文档

DELETE {index}/{type}/{id}

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman",serif;}

批量操作bulk  API

使用单一请求来实现多个文档的create、index、update 或 delete。

Bulk请求体格式:

{ action: { metadata }}\n

{ request body }\n

{ action: { metadata }}\n

{ request body }\n

POST _bulk
{ "delete": { "_index": "itsource", "_type": "employee", "_id": "123" }}
{ "create": { "_index": "itsource", "_type": "blog", "_id": "123" }}
{ "title": "我发布的博客" }
{ "index": { "_index": "itsource", "_type": "blog" }}
{ "title": "我的第二博客" }

批量获取

#批量获取方式一
GET _mget
{
"docs":[{
"_index":"itsource",
"_type":"blog",
"_id":"123"
},{
"_index":"itsource",
"_type":"blog",
"_id":"AWpXiEfhCq6ubXlpA9Ia",
"_source":"title" }]
} #批量获取方式二
GET itsource/blog/_mget
{
"ids":["123","AWpXiEfhCq6ubXlpA9Ia"]
}

分页查询

#分页查询
GET _search?size=3&from=2;
//查询条件位欸age=18的
GET crm/employees/_search?q=age:18
//查询10>age<30
GET crm/employees/_search?q=age[10 TO 30]

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman",serif;}

DSL查询

#DSL的查询方式
GET crm/employees/_search
{
"query" : {
"match" : {
"name" : "大哥"
}
}
}

案例:类似京东网站 查询关键字为iphone,国家为us的,价格范围6000到8000 价格降序,并# 且取前面2条:

GET shop/goods/_search
{
"query":{
"bool": {
"must": [
{"match": {
"name": "iphone"
}}
],
"filter": [{
"term":{
"local":"us"
}
},{
"range":{
"price":{
"gte":"5000",
"lte":"7000"
}
}
}]
}
},
"from": 1,
"size": 5,
"_source": ["id", "name", "type","price"],
"sort": [{"price": "desc"}]

在java中的操作为

 public class elasticTest {

     //取得clean对象
public TransportClient getClient() throws UnknownHostException {
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
return client; }
//添加数据
@Test
public void getCreated() throws Exception {
TransportClient client = getClient();
//创建一个库
IndexRequestBuilder indexRequestBuilder = client.prepareIndex("crm", "user", "1");
//准备数据
Map<String, Object> mp = new HashMap();
mp.put("id", 2);
mp.put("name", "kg");
mp.put("age", 18);
//将数据放入到库中,并且将数据读取出来
IndexResponse indexResponse = indexRequestBuilder.setSource(mp).get();
System.out.println(indexResponse);
}
//修改数据
@Test
public void update() throws Exception{
TransportClient client = getClient();
Map mp=new HashMap();
mp.put("id", 2);
mp.put("name", "黄巢");
mp.put("age", 35);
UpdateResponse response = client.prepareUpdate("crm", "user", "1").setDoc(mp).get();
GetResponse fields = client.prepareGet("crm", "user", "1").get();
System.out.println(fields.getSource()); }
//进行删除
@Test
public void testdelete() throws Exception{
TransportClient client = getClient();
DeleteResponse response = client.prepareDelete("crm", "user", "1").get();
System.out.println(response);
}
//批量添加
@Test
public void BUlk() throws Exception{
TransportClient client = getClient();
BulkRequestBuilder bulk = client.prepareBulk();
for (int i=0;i<10;i++){
Map map=new HashMap();
map.put("id", i);
map.put("age", 6+i);
map.put("name", "zhansan"+i); bulk.add(client.prepareIndex("crm","suer",i+"").setSource(map));
}
BulkResponse response = bulk.get(); SearchRequestBuilder search = client.prepareSearch("crm", "suer");
System.out.println(search); if (response.hasFailures()){
System.out.println("err");
}
client.close();
} @Test
public void testQuery() throws Exception{
TransportClient client = getClient();
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
//匹配值
List<QueryBuilder> must = boolQuery.must();
must.add(QueryBuilders.termQuery("name", "zhansan1")); //过滤
List<QueryBuilder> filter = boolQuery.filter();
filter.add(QueryBuilders.rangeQuery("age").gte("6").lte(10)); //设置分页
SearchResponse response = client.prepareSearch("crm")
.setFrom(0).setSize(3)
.setQuery(boolQuery)
.addSort("id", SortOrder.DESC).get(); System.out.println("总条数"+response.getHits().getTotalHits());
//第一次gethits表示获取到命中条数,第二次表示获取得到命中条数的数组
SearchHit[] hits = response.getHits().getHits();
//遍历数组得到具体的值
for (SearchHit hit : hits) {
System.out.println(hit.getSource());
} }
}

ElasticSearch的基本认识和基本操作的更多相关文章

  1. 【ELK】【ElasticSearch】3.es入门基本操作

    docker安装elasticSearch步骤 ================================================================== 本篇参考: htt ...

  2. Elasticsearch 7.x文档基本操作(CRUD)

    官方文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html 1.添加文档 1.1.指定文档ID PUT ...

  3. Elasticsearch 学习总结 - 相关配置补充说明

    一.   Elasticsearch的基本概念 term索引词,在elasticsearch中索引词(term)是一个能够被索引的精确值.foo,Foo Foo几个单词是不相同的索引词.索引词(ter ...

  4. 【ELK】【docker】6.Elasticsearch 集群启动多节点 + 解决ES节点集群状态为yellow

    本章其实是ELK第二章的插入章节. 本章ES集群的多节点是docker启动在同一个虚拟机上 ====================================================== ...

  5. 【ELK】【docker】【elasticsearch】1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安装ik分词器

    系列文章:[建议从第二章开始] [ELK][docker][elasticsearch]1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安 ...

  6. Elasticsearch系列---生产集群的索引管理

    概要 索引是我们使用Elasticsearch里最频繁的部分日常的操作都与索引有关,本篇从运维人员的视角,来玩一玩Elasticsearch的索引操作. 基本操作 在运维童鞋的视角里,索引的日常操作除 ...

  7. Elasticsearch笔记二之Curl工具基本操作

    Elasticsearch笔记二之Curl工具基本操作 简介: Curl工具是一种可以在命令行访问url的工具,支持get和post请求方式.-X指定http请求的方法,-d指定要传输的数据. 创建索 ...

  8. ElasticSearch 全文检索— ElasticSearch 基本操作

    REST 简介-定义 REST (REpresentation State Transfer)描述了一个架构样式的网络系统,比如 web 应用程序.它首次出现在 2000 年 Roy Fielding ...

  9. ElasticSearch之安装及基本操作API

    ElasticSearch 是目前非常流行的搜索引擎,对海量数据搜索是非常友好,并且在高并发场景下,也能发挥出稳定,快速特点.也是大数据和索搜服务的开发人员所极力追捧的中间件.虽然 ElasticSe ...

随机推荐

  1. 12-ssm中的description The request sent by the client was syntactically incorrect.

    此问题一般是在前端的数据传回是封装成对象失败的情况: 1.对象名不一致: 2.对象的数据类型不一致: 特别注意日期类型的: 如果前端是date数据类型的话: 传入的日期有问题 在pojo类中限定 @D ...

  2. vsftp上传文件出现553 Could not create file

    没有权限创建文件或是目录,原因是selinux引起的登陆问题. 通过如下命令查看状态: > sestatus -b|grep ftp 设置allow_ftpd_full_access为on. 在 ...

  3. Spring框架的AOP技术(注解方式)

    1. 步骤一:创建JavaWEB项目,引入具体的开发的jar包 * 先引入Spring框架开发的基本开发包 * 再引入Spring框架的AOP的开发包 * spring的传统AOP的开发的包 * sp ...

  4. 图像获取与采集及图像格式与Region介绍——第2讲

    一.图像获取与采集 1.本地图片读取 ① 单张读取 直接传入图片路径即可,可以用绝对路径,也可以用相对路径: read_image (Image, 'C:/Users/Administrator/De ...

  5. 都是假的!这位小姐姐 P 的图,认真看你就输了!

    开门见山,先来看张图: 肯定有不少小伙伴用不屑的语气说,嗬!一看就是 P 的! 是的,任谁都能一眼看出来是假的.但你可能想象不到,这张图的原始素材是有多么……支离破碎,熊是动物园里的,小孩是在家门口站 ...

  6. 【UXPA大赛企业专访】Mockplus:“设计替代开发”将成为现实

    “过去,是‘设计服务于开发’,现在,我认为是‘设计驱动开发’,而在不远的将来,随着AI的落地.大数据和云计算能力的提升,‘设计替代开发’将成为现实.Mockplus也正在为此部署并行动.” 近日,UX ...

  7. 子查询 in 潜在的问题 - 建议最好别用

    转至:http://wiki.lessthandot.com/index.php/Subquery_typo_with_using_in Subquery typo with using in Fro ...

  8. KbmMW 服务器架构简介

    kbmmw 由于文档比较少,很多同学开始用时很难理解.一直准备写一个关于kbmmw 架构的东西. 这几天与红鱼儿(blog)研究服务器线程时,整理了一下,大概画了一下kbmmw (版本4.5)服务器的 ...

  9. 2018.10.15 NOIP训练 水流成河(换根dp)

    传送门 换根dp入门题. 貌似李煜东的书上讲过? 不记得了. 先推出以1为根时的答案. 然后考虑向儿子转移. 我们记f[p]f[p]f[p]表示原树中以ppp为根的子树的答案. g[p]g[p]g[p ...

  10. 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)

    Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...