elasticsearch 简要指南-安装及简单测试,elasticsearch指南
elasticsearch 简要指南-安装及简单测试
主要拿elasticsearch做全文检索,elasticsearch所存储的数据都是持久化到硬盘的。
安装前准备
- JDK1.7
- 建议下载rtf中文分词版,https://github.com/medcl/elasticsearch-rtf
- 建议下载Google应用–sense作为调试工具,应用图标为一个绿树,可以方便的使用dsl语法
安装
运行bin目录的elasticsearch.bat
访问成功
需要理解的
简单测试
- 插入数据
PUT /megacorp/employee/1
{
"first_name" : "吴",
"last_name" : "寒冷",
"age" : 25,
"about" : "我喜欢打篮球",
"interests": [ "篮球", "吉他" ]
}
PUT /megacorp/employee/2
{
"first_name" : "吴",
"last_name" : "甜甜",
"age" : 26,
"about" : "我喜欢游泳,篮球",
"interests": [ "英语" ]
}
PUT /megacorp/employee/3
{
"first_name" : "韩",
"last_name" : "萌甜",
"age" : 22,
"about": "我喜欢吉他,足球s",
"interests": [ "旅游" ]
}
- 检索
检索
GET /megacorp/employee/1
搜索全部员工
GET /megacorp/employee/_search
搜索具体条件
GET /megacorp/employee/_search
{
"query" : {
"match" : {
"last_name" : "甜"
}
}
}
- 高级检索等
GET /megacorp/employee/_search
{
"query" : {
"filtered" : {
"filter" : {
"range" : {
"age" : { "gt" : 30 } <1>
}
},
"query" : {
"match" : {
"last_name" : "smith" <2>
}
}
}
}
}
<1> 这部分查询属于区间过滤器(range filter),它用于查找所有年龄大于30岁的数据——gt为"greater than"的缩写。
<2> 这部分查询与之前的match语句(query)一致。
全文搜索
GET /megacorp/employee/_search
{
"query" : {
"match" : {
"about" : "篮球"
}
}
}
GET /megacorp/employee/_search
{
"query" : {
"match" : {
"about" : " 我 游泳"
}
}
}
短语搜索
例如我们想要查询同时包含"喜欢"和"吉他"
GET /megacorp/employee/_search
{
"query" : {
"match_phrase" : {
"about" : " 喜欢 吉他"
}
}
}
高亮
GET /megacorp/employee/_search
{
"query" : {
"match_phrase" : {
"about" : "喜欢 吉他"
}
},
"highlight": {
"fields" : {
"about" : {}
}
}
}
- 可以在sense中测试相关代码
下一篇是elasticsearch java api相关,使用java客户端来操作elasticsearch
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。