Elasticsearch笔记
资料
官网: http://www.elasticsearch.org
.Net驱动: http://nest.azurewebsites.net/
教程: http://www.jianshu.com/p/05cff717563c
三级: 索引/类型/ID或操作符
对应: 数据库/表/ID
配置
启动服务: /es/elasticsearch -d
添加认证: http://segmentfault.com/a/1190000002803609
用户名: admin , admin_pw
关闭: curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown
关闭某一个索引: curl -XPOST http://localhost:9200/_cluster/nodes/[某一个索引]/_shutdown
查看索引: curl -XGet http://localhost:9200/_cluster/nodes
插件
Head
elasticsearch/bin/plugin -install mobz/elasticsearch-head
http://localhost:9200/_plugin/head/
Docker 安装 head
高版本的需要用新的方式安装 head
https://www.cnblogs.com/aubin/p/8018081.html
分词
IK官网:https://github.com/medcl/elasticsearch-analysis-ik
安装IK:bin/plugin -install medcl/elasticsearch-analysis-ik
安装分词需要 Jdk7,Maven,Git,在最新的ES(1.7.1)上,网上的文章大部分都是错的。正确方法:
http://my.oschina.net/xiaohui249/blog/232784
http://www.360doc.com/content/15/0114/13/16070877_440673208.shtml
如果这两篇文章存在有冲突的地方,使用后者。
步骤:
1.安装Jdk7,然后,再运行: set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_80\bin
注意:安装的Jdk版本一定要和服务器使用的JRE版本一致。否则ES启动后,不可使用。
2.安装 Maven,Git
3.进入 D:\ik ,运行: clone https://github.com/medcl/elasticsearch-analysis-ik
4.进入 D:\ik\elasticsearch-analysis-ik
5.运行:mvn clean package
6.生成的 jar 在 D:\ik\elasticsearch-analysis-ik\target\releases\elasticsearch-analysis-ik-1.4.0.zip , 其它的 jar 全是扯蛋。把它解出来。
附上链接: 百度网盘下载:elasticsearch-analysis-ik-1.4.0.zip
7. 把 解压缩的jar 拷贝到: ES_HOME/plugins/analysis-ik
8. 将下载目录中的ik目录拷贝到ES_HOME/config目录下面。
9.打开ES_HOME/config/elasticsearch.yml文件,在文件最后加入如下内容
index:
analysis:
analyzer:
ik:
alias: [ik_analyzer]
type: org.elasticsearch.index.analysis.IkAnalyzerProvider
ik_max_word:
type: ik
use_smart: false
ik_smart:
type: ik
use_smart: true
或:
index.analysis.analyzer.default.type: ik
10. 重新启动ES
11. 建一个索引,测试:
curl -XPut 'http://localhost:9200/index/_analyze?analyzer=ik&pretty=true' -d '
{
"text":"世界如此之大"
}'
Maven
安装教程:http://jingyan.baidu.com/article/1709ad808ad49f4634c4f00d.html
官网:http://maven.apache.org/download.cgi
Git
下载:http://www.git-scm.com/download/win
过程
1. 创建索引: Put ~/index
2. 获取所有Index: Get ~/_aliases
3. 创建别名: Put ~/<Index>/_alias/<Index_Alias>
4. 创建模板: Put ~/<index>/_mapping/<type> {type: {properties: { "列": { type:"string" }, "列2" : { type: { Id: { type: "int"} , Name: { type: "string"} } } }}}
对于《列2》来说,是一个对象类型,它可以是对象,也可以是对象数组。
更复杂的实例:
{
"hr": {
"properties": {
"ResumeName": {
"type": "string"
},
"Source": {
"type": "integer"
},
"PersonInfo": {
"properties": {
"Name": {
"type": "string",
"analyzer": "ik",
"include_in_all": true
},
"Sex": {
"type": "integer",
"analyzer": "ik",
"include_in_all": true
},
"BirthDay": {
"type": "date",
"analyzer": "ik",
"include_in_all": true
},
"Mobile": {
"type": "string"
},
"StartWorkAt": {
"type": "date",
"analyzer": "ik",
"include_in_all": true
},
"LiveCity": {
"type": "string",
"analyzer": "ik",
"include_in_all": true
},
"JobWantedStatus": {
"type": "integer",
"analyzer": "ik",
"include_in_all": true
},
"NativePlace": {
"type": "string"
},
"MonthlySalary": {
"type": "integer"
},
"YearSalary": {
"type": "integer"
},
"National": {
"type": "integer"
},
"IDCarNumber": {
"type": "string"
},
"Height": {
"type": "integer"
},
"MaritalStatus": {
"type": "integer"
},
"WxNumber": {
"type": "string"
},
"QqNumber": {
"type": "integer"
},
"LiveAddress": {
"type": "string"
},
"HomePage": {
"type": "string"
}
}
},
"Intention": {
"properties": {
"Keyword": {
"type": "string"
},
"SelfEvaluation": {
"type": "string"
},
"ExpectWorkIn": {
"type": "string",
"analyzer": "ik",
"include_in_all": true
},
"IndustryID": {
"type": "integer"
},
"IndustryName": {
"type": "string"
},
"PositionID": {
"type": "integer"
},
"PositionName": {
"type": "string"
},
"Nature": {
"type": "integer"
},
"ExpectSalary": {
"type": "integer",
"analyzer": "ik",
"include_in_all": true
},
"ArriveAt": {
"type": "date"
}
}
},
"Education": {
"properties": {
"StartAt": {
"type": "date"
},
"EndAt": {
"type": "date"
},
"School": {
"type": "string"
},
"Major": {
"type": "string",
"analyzer": "ik",
"include_in_all": true
},
"Education": {
"type": "integer",
"analyzer": "ik",
"include_in_all": true
},
"Remark": {
"type": "string"
},
"IsForeign": {
"type": "boolean"
}
}
},
"Experience": {
"properties": {
"StartAt": {
"type": "date"
},
"EndAt": {
"type": "date"
},
"Corporation": {
"type": "string"
},
"IndustryID": {
"type": "integer"
},
"IndustryName": {
"type": "string"
},
"Size": {
"type": "integer"
},
"Nature": {
"type": "integer"
},
"PositionID": {
"type": "integer"
},
"PositionName": {
"type": "string"
},
"Remark": {
"type": "string"
},
"WorkTimeType": {
"type": "integer"
}
}
},
"Train": {
"properties": {
"StartAt": {
"type": "date"
},
"EndAt": {
"type": "date"
},
"TrainingInstitution": {
"type": "string"
},
"TrainingPlace": {
"type": "string"
},
"TrainingCourse": {
"type": "string"
},
"Certificate": {
"type": "string"
},
"Remark": {
"type": "string"
}
}
},
"Language": {
"properties": {
"LanguageType": {
"type": "integer"
},
"Degree": {
"type": "integer"
},
"Level": {
"type": "string"
}
}
},
"AdditionalInfo": {
"properties": {
"Subject": {
"type": "string"
},
"Content": {
"type": "string"
}
}
},
"Certificate": {
"properties": {
"Name": {
"type": "string"
},
"GetAt": {
"type": "date"
},
"Score": {
"type": "string"
}
}
},
"Project": {
"properties": {
"StartAt": {
"type": "date"
},
"EndAt": {
"type": "date"
},
"Name": {
"type": "string",
"analyzer": "ik",
"include_in_all": true
},
"Development": {
"type": "string"
},
"Remark": {
"type": "string"
},
"MyDuty": {
"type": "string"
}
}
},
"ItSkill": {
"properties": {
"Name": {
"type": "string"
},
"UseTime": {
"type": "string"
},
"Degree": {
"type": "integer"
}
}
},
"TxtContent": {
"type": "string",
"analyzer": "ik",
"include_in_all": true
},
"OtherContent": {
"type": "string",
"analyzer": "ik",
"include_in_all": true
}
}
}
}
Es模板
5. 获取映射信息: Get ~/<index>/_mapping/<type>
6. 查看所有的索引及类型信息: Get ~/_mapping
7. 查看状态:
http://blog.chinaunix.net/uid-532511-id-4854331.html
健康状态: curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
8. 集群状态:
curl -XGET 'http://localhost:9200/_cluster/state?pretty'
curl -XGET 'http://localhost:9200/_cluster/stats?human&pretty'
9. 节点状态:
curl -XGET 'http://localhost:9200/_nodes/stats?pretty'
curl -XGET 'http://localhost:9200/_nodes/stats/os,process?pretty'
curl -XGET 'http://localhost:9200/_nodes?pretty'
curl -XGET 'http://localhost:9200/_nodes/process?pretty'
curl -XGET 'http://localhost:9200/_nodes/os?pretty'
curl -XGET 'http://localhost:9200/_nodes/settings?pretty'
10. 本机节点状态:
curl -XGET 'localhost:9200/_nodes/_local?pretty'
curl -XGET 'localhost:9200/_nodes/_local/network?pretty'
查询也可以针对子节点进行:
curl -XGET 'http://localhost:9200/_nodes/子节点?pretty'
Mapping
官网类型定义:https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html
官网复合类型: https://www.elastic.co/guide/en/elasticsearch/guide/current/complex-core-fields.html
复合类型是指,值是:数组,对象。
任何值,都可以按定义的数据类型保存为一个值,或一个该值的数据。
知识点
springboot 两个端口,两种驱动
建议使用 9200 的 Rest 方式。
http://www.jb51.net/article/127390.htm
查询
http://www.cnblogs.com/zhangchenliang/p/4195406.html
排序 function_score函数
官方:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
文章: http://blog.csdn.net/dm_vincent/article/details/42201789
权重
字段后使用 ^2 表示该字段权限是2 如:
query:"title:中国^2+title:北京-content:美国" 表示:title中包含中国的部分权重是2 ,同时 title中包含北京,同时, content中不包含 美国。
返回列
_source 返回该节点及子节点
"_source": {
"Id": "8a7229609bd841fcb7ed2ffc68a5a01f",
"PersonInfo": {
"Name": "马少明"
}
},
fields 只能返回叶子节点
"fields": {
"PersonInfo.Name": [
"马少明"
],
"Id": [
"8a7229609bd841fcb7ed2ffc68a5a01f"
]
},
问题
1. 提交的Json,不能带有如下属性 : id , _id , 但可以是: Id ,ID !
ES里的系统字段包含: _index,_type,_id,_score
2. 提交的Json,第一次提交,会建立一个模板,如果第二次提交的数据与第一次提交的数据在格式有冲突,则不能创建。
典型的例子是,第一次提交的数据是,有一个对象数组,但值是空的。 第二次提交的对象数据有值,则不能提交。
需要修改数据模板。
修改索引:
http://www.cnblogs.com/Creator/p/3722408.html
http://www.cnblogs.com/tianjixiaoying/p/4424076.html
3.健康值红了:
http://localhost:9200/wy/_optimize
4. 使用 function_score 的文章: http://blog.csdn.net/dm_vincent/article/details/42201721 , 它里面写的: Get _search 是错的,应该是 Post _search
Post ~/_search or ~/wy/_search or ~/wy/hr/_search
{
"query": {
"function_score": {
"filter": {
"term": {
"BirthYear": "1980"
}
},
"functions": [
{
"filter": {
"term": {
"NowCity": "北京"
}
},
"weight": 1
}
],
"score_mode": "sum"
}
}
}
使用SQL进行ES查询
其实ES官方早就应该实现这个功能: http://www.open-open.com/lib/view/open1447747736056.html
Elasticsearch笔记的更多相关文章
- Elasticsearch笔记九之优化
Elasticsearch笔记九之优化 ).get(); } curl命令可以在linux中建立一个定时任务每天执行一次,同样java代码也可以建立一个定时器来执行. 2:内存设置之前介绍过es集群有 ...
- Elasticsearch笔记八之脑裂
Elasticsearch笔记八之脑裂 概述: 一个正常es集群中只有一个主节点,主节点负责管理整个集群,集群的所有节点都会选择同一个节点作为主节点所以无论访问那个节点都可以查看集群的状态信息. 而脑 ...
- Elasticsearch笔记七之setting,mapping,分片查询方式
Elasticsearch笔记七之setting,mapping,分片查询方式 setting 通过setting可以更改es配置可以用来修改副本数和分片数. 1:查看,通过curl或浏览器可以看到副 ...
- Elasticsearch笔记二之Curl工具基本操作
Elasticsearch笔记二之Curl工具基本操作 简介: Curl工具是一种可以在命令行访问url的工具,支持get和post请求方式.-X指定http请求的方法,-d指定要传输的数据. 创建索 ...
- 白日梦的Elasticsearch笔记(一)基础篇
目录 一.导读 1.1.认识ES 1.2.安装.启动ES.Kibana.IK分词器 二.核心概念 2.1.Near Realtime (NRT) 2.2.Cluster 2.3.Node 2.4.In ...
- Elasticsearch笔记六之中文分词器及自定义分词器
中文分词器 在lunix下执行下列命令,可以看到本来应该按照中文"北京大学"来查询结果es将其分拆为"北","京","大" ...
- Elasticsearch笔记四之配置参数与核心概念
在es根目录下有一个config目录,在此目录下有两个文件分别是elasticsearch.yml和logging.yml. logging.yml是日志文件,es也是使用log4j来记录日志的,我在 ...
- Elasticsearch笔记三之版本控制和插件
版本控制 1:关系型数据库使用的是悲观锁,数据被读取后就被锁定其他的线程就无法对其进行修改. 2:ex使用的是乐观锁,数据被读取后其他程序还可以对其进行修改,而执行修改时发现此数据已经被修改则修改就会 ...
- Elasticsearch笔记五之java操作es
Java操作es集群步骤1:配置集群对象信息:2:创建客户端:3:查看集群信息 1:集群名称 默认集群名为elasticsearch,如果集群名称和指定的不一致则在使用节点资源时会报错. 2:嗅探功能 ...
随机推荐
- controller错误统一处理--------@ExceptionHandler
用@RequestBody,@ResponseBody,不费吹灰之力就解决了JSon自动绑定.接着就发现,如果遇到RuntimeException,需要给出一个默认返回JSON 三种方式: 1.当这个 ...
- Ubuntu 远程登录服务器--ssh的安装和配置
Ubuntu的安装包居然不自带openssh服务器,所以若要使用ssh远程登录Ubuntu主机,需要首先安装ssh服务器: sudo apt-get install openssh-server 安装 ...
- Futoshiki求解
Futoshiki求解 Futoshiki是对于一个n的方阵,需要满足如下条件: ·每一行和每一列的元素都不能重复,即每一行和每一列1到n,n个数字都出现,且只出现一次. ·同一行或同一列中相邻两个元 ...
- 我开发的SNMP编译器和浏览器
我开发的SNMP编译器和浏览器 什么是SNMP SNMP(Simple Network Management Protocol,简单网络管理协议)的前身是简单网关监控协议(SGMP),用来对通信线路进 ...
- 阻塞非阻塞,同步异步四种I/O方式
举一个去书店买书的例子吧: (同步)阻塞: 你去书店买书,到柜台告诉店员,需要买一本APUE,然后一直在柜台等.(阻塞) 店员拿到书以后交给你. (同步)非阻塞: 你去书店买书,到柜台告诉店员A,需要 ...
- jQuery操作Table tr td常用的方法
虽然现在DIV+CSS进行页的布局大行其道,但是很多地方使用table还是有很多优势,用table展示数据是比较方便的,下面汇总了jQuery操作Table tr td常用的方法,熟记这些操作技巧,下 ...
- 【温故Delphi】之VCL消息机制小结
TObject消息分派 procedure Dispatch(var Message); virtual; #负责分派消息到特定VCL组件的事件处理函数 procedure DefaultHandle ...
- Unity加载模块深度解析(Shader)
作者:张鑫链接:https://zhuanlan.zhihu.com/p/21949663来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 接上一篇 加载模块深度解析(二 ...
- 第三章 文件IO复习
open(const char * path, int flag.../*mode_t*/) #include <fcntl.h> path:绝对路径 flag:O_RDONL ...
- JavaScript标准库之——JSON
JSON 对象包含了两个方法,一是解析 JavaScript Object Notation (JSON),二是将值转换为 JSON.这个对象本身不能被调用或者作为构造函数,除了它的这两个方法属性外 ...