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:嗅探功能 ...
随机推荐
- [转]protobuf-2.5.0.tar.gz的下载与安装
protobuf-2.5.0.tar.gz的下载与安装 原文地址:http://blog.csdn.net/tdmyl/article/details/31811317 版权声明:本文为博主原创文章, ...
- 关于移动端input框 在微信中 和ios中无法输入文字的问题
这个是一个提交的页面但是总是无法输入进去文字 在uc中是可以的 但是在微信中 或者ios自带浏览器是无法输入的 绞尽脑汁 找了半天 才发现自己多加了一段代码(这个代码是模版中自带的 我靠) ...
- zend studio常用快捷键
1.提示符助手快捷键 alt+/ 你可以自定义 window->keys->Content assist->Binding 2.复制当前行 alt+ctrl+下 3.删除 ctrl+ ...
- 从github上获取资源速度慢的解决办法
今天在github上clone一个仓库的时候,速度非常慢,只有3kb/s,开代理也没用,网上找到的各种git config的方法也没有用,最后想到设置hosts试试.于是在git的安装目录下找到了/e ...
- 【Mail】邮件的基础知识和原理
电子邮件概念 电子邮件是-种用电子手段提供信息交换的通信方式,是互联网应用最广的服务.通过网络的电子邮件系统,用户可以以非常低廉的价格(不管发送到哪里,都只需负担网费).非常快速的方式(几秒钟之内可以 ...
- [C#.net] SendMessage
函数功能:该函数将指定的消息发送到一个或多个窗口.此函数为指定的窗口调用窗口程序,直到窗口程序处理完消息再返回.该函数是应用程序和应用程序之间进行消息传递的主要手段之一. 函数原型:LRESU ...
- javascript总结
javascript:它是一种script脚本语言 脚本语言:就是可以和HTML混合在一起使用的语言,可以用来在IE的客 户端进行程序编制,从 ...
- 选择HttpHandler还是HttpModule?
阅读目录 开始 理解ASP.NET管线 理解HttpApplication 理解HttpHandler 理解HttpModule 三大对象的总结 案例演示 如何选择? 最近收到几个疑问:HttpHan ...
- 集成TBS(腾讯浏览服务)x5内核的webView
由于公司产品需要展示html5页面,一开始我使用的是android自带webview,一些简单的页面没什么问题,但是碰到比较复杂的页面就让人无语了. 1.Android各大厂商都有自己定制的ROM,导 ...
- H5、CSS3属性的支持性以及flex
一.项目中用到一个flex属性,但是应用了flex的父容器只设置了width,没有设置height,此时每一个应用了上面提到的属性的样式的div都重叠在了一起,在IE10,IE11出问题,IE9没有问 ...