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:嗅探功能 ...
随机推荐
- apache 指定的网络名不再可用 原因及解决方法
1.出现问题状况: 出现问题网站:http://www.ayyzz.cn/ 前段时间作文大全网出现有时候比较慢,有时候“找不到网页”404错误:另外在error.log里也报错: [Mon May 0 ...
- C语言实现 字符串过滤并修改并返回个数
基本问题:给定一个strContent,strWord,使用strWord 匹配strContent,匹配成功,将匹配部分全部替换为‘*’ ,并返回匹配成功个数.注意不能使用库函数. 例如:strCo ...
- ubuntu linux mysql 安装 基本操作 命令
mysql --help #如果有信息证明系统已经安装了mysql mysql -V #查看版本号 netstat -tap|grep mysql #检查mysql是否在启动状态 卸载mysql: s ...
- Linux下使用Eclipse开发Hadoop应用程序
在前面一篇文章中介绍了如果在完全分布式的环境下搭建Hadoop0.20.2,现在就再利用这个环境完成开发. 首先用hadoop这个用户登录linux系统(hadoop用户在前面一篇文章中创建的),然后 ...
- Wind7系统下 wifi设置
netsh wlan set hostednetwork mode=allow ssid=pass:123456789 key=123456789 netsh wlan set hostednetw ...
- 怎样防止重复发送 Ajax 请求?
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:长天之云链接:http://www.zhihu.com/question/19805411/answer/15465427来源 ...
- CAD二次开发
用C#有一段时间了,由于单位需要,开始接触CAD二次开发,网上一搜,加入CAD开发的群,零零碎碎看了一些文章和博客,没有系统地的知识,能解决一些小问题.最近开始系统学习,再次推荐两本书,一本事纸质版的 ...
- FibonacciSequence
import java.util.Scanner; public class Fibonacci { public static void main(String[] args) { int n; f ...
- linux split 命令 将一个大的文件拆分成若干小文件
. 以行数拆分 -l 参数: 原始文件 拆分后文件名前缀 例:以50行对文件进行拆分 big.txt small_ 拆分后会生成 small_aa small_ab small_ac ... . 以大 ...
- C# 实现 任意多边形切割折线算法
1. 内容简介 本文旨在解决任意多边形切割折线,获取切割之后的折线集合. 本文实现的算法内容包括:判断两条线段是否相交,如若相交,获取交点集合.对线上的点集,按斜率方向排序.判断点是否在多边形内 ...