下载安装的地址,华为镜像网站,github
解压安装ElasticSearch,配置跨域
打开文件,在最下面添加运行跨域,且跨域的主机IP为所有。
COPYhttp.cors.enabled: true
http.cors.allow-origin: "*"
点击elasticsearch.bat 即可启动,访问http://127.0.0.1:9200 就可以看到是否成功
出现elasticsearch的配置说明json即说明成功
解压安装ElasticSearch-head
1、需要node.js环境和python环境,npm包管理工具
从GitHub下载完后打开文件夹,用cmd进入到文件夹里面,输入以下命令,即可启动。
COPYnpm install
npm run start
输入框中输入elasticsearch的ip地址和端口号,点击连接即可看到集群信息
2、 使用谷歌自带的插件
谷歌浏览器打开以下链接,点击安装即可。
http://extb.cqttech.com/search/elasticsearch%2520head
打开解压好的kibana文件夹,配置kibana
进入config文件夹
编辑kibana.yml,加上中文国际化,使得kibana汉化。
COPYi18n.locale: "zh-CN"
到bin目录,点击kibana.bat启动即可
打开浏览器,访问 http://localhost:5601
看到以下页面即为成功
下载ik分词器,配置自己的字典
下载地址:https://github.com/medcl/elasticsearch-analysis-ik
然后将文件夹复制到elasticsearch的插件文件夹plugins里面
进入文件夹,到config文件夹里面,创建一个××.dic文件,打开编辑属于自己的字典。
保存后,配置到ik分词器里面
配置完后所有程序都得重启~
打开kibana进入后,点击扳手,进入控制台
ik_smart 为最少切分 ik_max_word为细粒度划分!会去匹配字典!
COPYGET _analyze
{
"analyzer": "ik_smart",
"text": "码农人"
}
COPYGET _analyze
{
"analyzer": "ik_max_word",
"text": "码农人"
}
ik_max_word 会穷尽字典所有可能的组词。
COPY//创建索引
PUT /test2
{
"mappings": {
"properties": {
"name": {
"type": "text"
},
"age":{
"type": "long"
},
"birthday":{
"type": "date"
}
}
}
}
GET _cat/indices?
// 删除索引
DELETE /test1
// 插入文档
PUT /hcode/user/
{
"name": "hhh",
"age": ,
"tags":["帅哥","大哥"]
}
PUT /hcode/user/
{
"name": "xxx",
"age": ,
"tags":["sb","db"]
}
PUT /hcode/user/
{
"name": "qqq",
"age": ,
"tags":["美女","靓女"]
}
// 获取文档信息
GET /hcode/user/
//更新文档
POST /hcode/user//_update
{
"doc":{
"name": "hzh"
}
}
// 查询文档 条件为name=hzh
GET /hcode/user/_search?q=name:hzh
// 插入文档
PUT /hcode/user/
{
"name": "hzh5",
"age": ,
"tags":["sb","db"]
}
//条件查询,获取name=hzh,且只返回name,tags的数据
GET /hcode/user/_search
{
"query": {
"match": {
"name": "hzh"
}
},
"_source": ["name","tags"]
}
// 条件查询,获得匹配name=hzh,且按age降序 分页返回第1页,每页数量为1
GET /hcode/user/_search
{
"query": {
"match": {
"name": "hzh"
}
},
"sort": [{
"age":{
"order": "desc"
}
}
],
"from": ,
"size":
}
// 条件查询 name=hzh and age = 3
GET /hcode/user/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "hzh"
}
},
{
"match": {
"age":
}
}
]
}
}
}
// 条件查询 name=hzh or age=3
GET /hcode/user/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"name": "hzh"
}
},
{
"match": {
"age":
}
}
]
}
}
}
// 条件查询 age !=3
GET /hcode/user/_search
{
"query": {
"bool": {
"must_not": [
{
"match": {
"age":
}
}
]
}
}
}
// 条件查询 name=hzh and 3<=age<=10
GET /hcode/user/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "hzh"
}
}
],
"filter":
{
"range": {
"age": {
"gte": ,
"lte":
}
}
}
}
}
}
// 查询后 对应field高亮!
GET /hcode/user/_search
{
"query": {
"match": {
"name": "hzh"
}
}
, "highlight": {
"pre_tags": "<p style='color:red'>",
"post_tags": "</p>",
"fields": {
"name":{}
}
}
}