elasticsearch

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: 1、Elasticsearch的堆栈内存设置建议![image.png](https://upload-images.jianshu.io/upload_images/9967595-3292925868e93be0.
1、Elasticsearch的堆栈内存设置建议
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3292925868e93be0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2、elasticsearch.yml设置中文分词器:
 /usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.4/elasticsearch-analysis-ik-6.5.4.zip
//安装完,在elasticsearch.yml中添加配置
index.analysis.analyzer.default.type: ik
3、关闭elasticsearch
curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown
![image.png](https://upload-images.jianshu.io/upload_images/9967595-597bda51ab5a749b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-a061dc15af281ff0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4、监控客户端状态的插件head;
http://localhost:9200/_plugin/head
![image.png](https://upload-images.jianshu.io/upload_images/9967595-131208ff47feb219.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
5、Marvel 图形化监控客户端
http://lcalhost:9200/_plugin/marvel/
![image.png](https://upload-images.jianshu.io/upload_images/9967595-25df51a52e04978d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
6、Health 查看集群状态
![image.png](https://upload-images.jianshu.io/upload_images/9967595-1eb5aac0ef86fb76.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
7、架构
![image.png](https://upload-images.jianshu.io/upload_images/9967595-6d2fa8ae7f585f40.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
8、http://ip:9200/index/type/id
index: dbname
type: dbtable
GET/POST/PUT/DELETE
?pretty 增强可读性
9、mapping 映像,相当于数据类型
10、搜索参数:_search?q=location:Shanghai
11、实例
 创建索引文件test,用PUT方法创建
创建mapping文件,//不是elasticsearch的注释,mapping相当于对象
![image.png](https://upload-images.jianshu.io/upload_images/9967595-55727fa8223cb779.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-bc980c2df4e27a14.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
创建检索表达式
![image.png](https://upload-images.jianshu.io/upload_images/9967595-7487ac7ff86320af.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-6978ac7e171f65db.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-f580887a3130364c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-c1f0933acefca159.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-33acde1ea5017486.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
12、用XPUT方式创建索引
![image.png](https://upload-images.jianshu.io/upload_images/9967595-396f732ecbf51a0e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
用_settings修改索引
![image.png](https://upload-images.jianshu.io/upload_images/9967595-2afd3c96a10ea243.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
索引属性:number_of_replicas 索引的副本数量
blocks.read_only 只读 blocks.read  禁止读取 blocks.write blocks.metadata
调取索引的配置:curl -XGET http://ip:port/weibo/_settings
 http://xx/weibo1,weibo2/_settings
_all/_settings  所有索引
mar*/_settings
13、插入数据
![image.png](https://upload-images.jianshu.io/upload_images/9967595-857cc25c2c233cf4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
String,Integer,Long,Float,Double,Boolean,Null,Date
14、_stats 索引状态
![image.png](https://upload-images.jianshu.io/upload_images/9967595-f7e9099392bb797a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![image.png](https://upload-images.jianshu.io/upload_images/9967595-ab0c6cb6e6ca5a6c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
15、配置mapping
PUT /{index}/_mapping/{type}
PUT /index/type/_mapping -d '{
"wb":{
"properties":  {
"mymessage":{
"type":"String",
"store": true
}
}
}
}'
获取get /index/_mapping/type
_all/_mapping
获取索引某个字段  get /index/_mapping/type/field/user

删除DELETE
16、打开关闭索引文件
curl -XPOST /myindex/_open
curl -XPOST /myindex/_close
检索 curl -XHEAD /myindex -v
XDELETE
清空索引缓存  curl -XPOST /myindex/_cache/clear
刷新索引数据 curl -XPOST /myindex/_refresh
优化索引数据 curl -XPOST /myindex/_optimize
flush     /myindex/_flush
给索引配置分析器
![image.png](https://upload-images.jianshu.io/upload_images/9967595-e17aeeda8f953a70.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
临时使用分词器
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3b4dfdef9a5b8c85.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
获取文档指定信息
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3f0830339931d127.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
?pretty&fields=user 只显示user字段
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3f7407712179b1a7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
删除 curl -XDELETE ///
数据更新  xput
![image.png](https://upload-images.jianshu.io/upload_images/9967595-c5badaeee2c6d85e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-e5a34cb4cb634e3c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-513e0267eef33b66.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/9967595-d533ce540d148778.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

xpost + _mget? 批量获取
![image.png](https://upload-images.jianshu.io/upload_images/9967595-3716270a3e9d6bf0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
_source 获取数据
_query?q=user:xxx 
--------------------------------------------------------------------------------------
信息检索:curl -XGET ip/_search?q=hello&pretty=true
terms查询:不作分词
match_all:{}   查询所有
常规查询:+ -




相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
目录
相关文章
|
6月前
|
自然语言处理 Java 网络安全
ElasticSearch
ElasticSearch
77 2
|
6月前
|
Java 关系型数据库 API
ElasticSearch使用篇
ElasticSearch使用篇
|
6月前
|
存储 JSON 监控
Elasticsearch简单讲解
Elasticsearch简单讲解
78 0
|
存储 关系型数据库 MySQL
Elasticsearch(一)
Elasticsearch(一)
68 0
|
自然语言处理 索引
Elasticsearch(三)
Elasticsearch(三)
64 0
|
存储 关系型数据库 MySQL
Elasticsearch(二)
Elasticsearch(二)
62 0
一起来学ElasticSearch(十)
前言 目前正在出一个Es专题系列教程, 篇幅会较多, 喜欢的话,给个关注❤️ ~ 承接上文,上节给大家讲的es聚合还有一点内容,本节给大家更完~ 本文偏实战一些,为了方便演示,本节示例沿用上节索引,好了, 废话不多说直接开整吧~ 聚合排序 我们如何在聚合结果中进行自定义字段排序呢?
|
Java API 索引
还不会ElasticSearch?一文搞定
本文讲解Java操作ElasticSearch
175 1
下一篇
无影云桌面