当前位置:网站首页>Kibana操控ES
Kibana操控ES
2022-07-02 02:13:00 【CV工程师呀】
1.索引的操作
索引相当于mysql中的表
映射相当于mysql中的指定字段类型
索引不能修改
#查看es中索引
GET /_cat/indices
#查看es中索引和标题
GET /_cat/indices?v
#创建索引
PUT /products
#创建索引、指定映射
PUT /products
{
"mappings": {
"properties": {
"id":{
"type": "integer"
},
"title":{
"type": "keyword"
}
}
}
}
#查看映射
GET /products/_mapping
#删除索引
DELETE /products
2.文档的增删改查
文档相当于mysql中的一条记录
#添加文档 手动指定id
POST /products/_doc/1
{
"id":1,
"title":"小浣熊"
}
#添加文档 自动创建id
POST /products/_doc/
{
"title":"小熊猫"
}
#查询文档
GET /products/_doc/1
#删除文档
DELETE /products/_doc/1
#更新文档 会删除原始文档 ,再重新添加
PUT /products/_doc/1
{
"title":"小浣熊熊"
}
#更新文档 基于指定字段更新
POST /products/_doc/1/_update
{
"doc":{
"title":"小小浣熊"
}
}
3.文档的批量操作
对于批量操作数据不能换行,否则会报错
#批量增加文档
POST /products/_doc/_bulk
{"index":{"_id":2}}
{"id":2,"title":"腾讯"}
{"index":{"_id":3}}
{"id":3,"title":"米哈游"}
#批量添加、更新、删除文档
POST /products/_doc/_bulk
{"index":{"_id":4}}
{"id":4,"title":"甜不辣"}
{"update":{"_id":3}}
{"doc":{"title":"阿里"}}
{"delete":{"_id":2}}
4.文档的高级查询
#查询所有
GET /products/_search
{
"query":{
"match_all":{}
}
}
#term基于关键词查询
#在ES中中文单字分词,英文单词分词
#在ES中除了text类型分词,其余类型均不分词
GET /products/_search
{
"query":{
"term":{
"title":"阿里"
}
}
}
#范围查询
GET /products/_search
{
"query": {
"range": {
"price": {
"gte": 10, // 这里的gte代表大于等于,gt则代表大于
"lte": 20 // lte代表小于等于,lt则代表小于
}
}
}
}
#前缀查询
GET /products/_search
{
"query":{
"prefix":{
"title":{
"value": "小"
}
}
}
}
#wildcard通配符查询 ?匹配一个字符 *匹配多个字符
GET /products/_search
{
"query":{
"wildcard":{
"title":{
"value": "小?"
}
}
}
}
#根据id组查询
GET /products/_search
{
"query":{
"ids":{
"values": [1,3,4]
}
}
}
#模糊查询,不等同mysql的模糊查询,具体可百度
GET /products/_search
{
"query":{
"fuzzy":{
"title":"小浣猫"
}
}
}
#布尔查询
#must:必须匹配每个子查询,类似“与”
#should:选择性匹配子查询,类似“或”
#must_not:必须不匹配,不参与算分,类似“非”
#filter:必须匹配,不参与算分
GET /hotel/_search
{
"query": {
"bool": {
"must": [
{"term": {"city": "上海" }}
],
"should": [
{"term": {"brand": "皇冠假日" }},
{"term": {"brand": "华美达" }}
],
"must_not": [
{ "range": { "price": { "lte": 500 } }}
],
"filter": [
{ "range": {"score": { "gte": 45 } }}
]
}
}
}
#在多个字段中查询,会对关键字进行分词再进行查找
GET /products/_search
{
"query":{
"multi_match":{
"query":"浣猫",
"fields": ["title","description"]
}
}
}
#高亮
#高亮是对关键字高亮,因此搜索条件必须带有关键字,而不能是范围这样的查询。
#默认情况下,高亮的字段,必须与搜索指定的字段一致,否则无法高亮
#如果要对非搜索字段高亮,则需要添加一个属性:required_field_match=false
GET /hotel/_search
{
"query": {
"match": {
"FIELD": "TEXT" // 查询条件,高亮一定要使用全文检索查询
}
},
"highlight": {
"fields": { // 指定要高亮的字段
"FIELD": {
"pre_tags": "<em>", // 用来标记高亮字段的前置标签
"post_tags": "</em>" // 用来标记高亮字段的后置标签
}
}
}
}
#分页和升序
GET /hotel/_search
{
"query": {
"match_all": {}
},
"from": 0, // 分页开始的位置,默认为0
"size": 10, // 期望获取的文档总数
"sort": [
{"price": "asc"}
]
}
5.文档的过滤查询
过滤查询不会计算数据得分,第五节以前的查询是文档query查询,这会计算数据得分,影响查询的性能。在ES中是先进行过滤查询,再进行文档query查询。
GET /hotel/_search
{
"query": {
"bool": {
"must": [
{"term": {"city": "上海" }}
],
"should": [
{"term": {"brand": "皇冠假日" }},
{"term": {"brand": "华美达" }}
],
"must_not": [
{ "range": { "price": { "lte": 500 } }}
],
"filter": [
{ "range": {"score": { "gte": 45 } }}
]
}
}
}
边栏推荐
- Construction and maintenance of business websites [12]
- np.where 和 torch.where 用法
- trading
- C language 3-7 daffodils (enhanced version)
- CSDN insertion directory in 1 second
- Based on configured schedule, the given trigger will never fire
- What style of Bluetooth headset is easy to use? High quality Bluetooth headset ranking
- How to hide the scroll bar of scroll view in uniapp
- leetcode2312. Selling wood blocks (difficult, weekly race)
- How to batch add background and transition effects to videos?
猜你喜欢

New news, Wuhan Yangluo international port, filled with black technology, refreshes your understanding of the port

MySQL主从延迟问题怎么解决

734. Energy stone (greed, backpack)
![[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing](/img/ba/dcb276768b1a9cc84099f093677d29.png)
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing

Medical management system (C language course for freshmen)

No programming code technology! Four step easy flower store applet

Software No.1

MySQL如何解决delete大量数据后空间不释放的问题

Ar Augmented Reality applicable scenarios

分卷压缩,解压
随机推荐
Duplicate keys detected: ‘0‘. This may cause an update error. found in
如何用一款产品推动「品牌的惊险一跃」?
研发中台拆分过程的一些心得总结
The wave of layoffs in big factories continues, but I, who was born in both non undergraduate schools, turned against the wind and entered Alibaba
pytest 测试框架
How to execute an SQL in MySQL
Sword finger offer 47 Maximum value of gifts
How to use a product to promote "brand thrill"?
软件开发生命周期 --瀑布模型
[question] - why is optical flow not good for static scenes
new和malloc的区别
OpenCASCADE7.6编译
JMeter (I) - download, installation and plug-in management
剑指 Offer 62. 圆圈中最后剩下的数字
剑指 Offer II 031. 最近最少使用缓存
np.where 和 torch.where 用法
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
Construction and maintenance of business websites [11]
剑指 Offer 29. 顺时针打印矩阵
Construction and maintenance of business websites [10]