当前位置:网站首页>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 } }}
]
}
}
}
边栏推荐
- The middle element and the rightmost element of the shutter
- Start from scratch - Web Host - 01
- trading
- Deep learning: a solution to over fitting in deep neural networks
- 附加:信息脱敏;
- essay structure
- leetcode373. Find and minimum k-pair numbers (medium)
- leetcode2310. 个位数字为 K 的整数之和(中等,周赛)
- How to turn off debug information in rtl8189fs
- This is the report that leaders like! Learn dynamic visual charts, promotion and salary increase are indispensable
猜你喜欢

The concept, function, characteristics, creation and deletion of MySQL constraints

How to turn off debug information in rtl8189fs

How does MySQL solve the problem of not releasing space after deleting a large amount of data

Pytest testing framework

CSDN article underlined, font color changed, picture centered, 1 second to understand

If you want to rewind the video picture, what simple methods can you use?

Data analysis on the disaster of Titanic
![[technology development -21]: rapid overview of the application and development of network and communication technology -1- Internet Network Technology](/img/2d/299fa5c76416f74bd1a693c433dd09.png)
[technology development -21]: rapid overview of the application and development of network and communication technology -1- Internet Network Technology

花一个星期时间呕心沥血整理出高频软件测试/自动化测试面试题和答案

MySQL主从延迟问题怎么解决
随机推荐
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
leetcode2311. 小于等于 K 的最长二进制子序列(中等,周赛)
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
The smart Park "ZhongGuanCun No.1" subverts your understanding of the park
DNS domain name resolution
Leetcode face T10 (1-9) array, ByteDance interview sharing
flutter 中間一個元素,最右邊一個元素
oracle创建只读权限的用户简单四步走
Logging only errors to the console Set system property ‘log4j2. debug‘ to sh
Sword finger offer 29 Print matrix clockwise
【带你学c带你飞】3day第2章 用C语言编写程序(练习 2.3 计算分段函数)
Types of exhibition items available in the multimedia interactive exhibition hall
分卷压缩,解压
2022 Q2 - résumé des compétences pour améliorer les compétences
leetcode373. 查找和最小的 K 对数字(中等)
Duplicate keys detected: ‘0‘. This may cause an update error. found in
mysql列转行函数指的是什么
Flutter un élément au milieu, l'élément le plus à droite
正则表达式学习笔记
2022 Q2 - Summary of skills to improve skills