MAC ElasticSearch + Kibana 测试环境 Docker 安装 与 基本使用

_ElasticSearch+Kibana测试环境安装 _ docker pull elasticsearch:7.9.0 docker pull kibana:7.9.0 docker run -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -v /Users/val/Documents/my/elasticsearch/data:/usr/share/elasticsearch/data --name elasticsearch elasticsearch:7.9.0 docker exec -it elasticsearch /bin/bash docker run -d -p 5601:5601 --link=elasticsearch --name kibana kibana:7.9.0 _Kibana DevTools 基本使用 _ # 打开控制台 http://localhost:5601/app/dev\_tools#/console # 创建索引 PUT es_biz_trade_product { "settings": { "number_of_shards": 1, "number_of_replicas": 1 } } # 删除索引 DELETE es_biz_trade_product # 查询索引 GET es_biz_trade_product # 查询索引是否存在 HEAD es_biz_trade_product # 创建映射关系(数据库列) type: 类型,text/long/short/integer/object index: 是否索引,默认为true store: 是否存储,默认为false analyzer: 分词器 PUT es_biz_trade_product/_mapping { "properties": { "id": { "type": "long" }, "name": { "type": "text" }, "original_price": { "type": "double" }, "current_price": { "type": "double" } } } # 查询映射关系 GET es_biz_trade_product/_mapping

添加 / 更新数据 # 新增 POST es_biz_trade_product/_doc { "id": "1", "name": "AI商品", "original_price": 32.5, "current_price": 30.5 } # 修改 POST es_biz_trade_product/_doc/qu7mCnQB9QusIJpJXdEe { "id": "1", "name": "商品", "original_price": 32.5, "current_price": 30.5 } # 新增 POST es_biz_trade_product/_doc { "id": "2", "name": "商品", "original_price": 40.5, "current_price": 38.5 } # 查询所有 GET es_biz_trade_product/_search # 根据ID查询单个 GET es_biz_trade_product/_doc/7e7oCnQB9QusIJpJ6NEv # 删除数据 DELETE es_biz_trade_product/_doc/7e7oCnQB9QusIJpJ6NEv

_#####查询使用 _ # 查询所有 GET es_biz_trade_product/_search # 根据ID查询单个 GET es_biz_trade_product/_doc/7e7oCnQB9QusIJpJ6NEv GET /索引库名/_search { "query":{ "查询类型":{ "查询条件":"查询条件值" } } } 返回 time_out:是否超时 _shards:分片信息 hits:搜索结果总览对象 total:搜索到的总条数 max_score:所有结果中文档得分的最高分 hits:搜索结果的文档对象数组,每个元素是一条搜索到的文档信息 _index:索引库 _type:文档类型 _id:文档id _score:文档得分 _source:文档的源数据 # 查询所有 GET es_biz_trade_product/_search { "query": { "match_all": { } } } # 匹配查询(模糊分词匹配,词之间是OR关系) GET es_biz_trade_product/_search { "query": { "match": { "name": "里斯本" } } } # 匹配查询(全匹配,词之间是and关系),里斯本,过滤了 里斯 GET es_biz_trade_product/_search { "query": { "match": { "name": { "query": "里斯本", "operator": "and" } } } } # 最小匹配度查询(50%类似OR,100%类似AND) GET es_biz_trade_product/_search { "query": { "match": { "name": {"query":"里斯本", "minimum_should_match": "100%"} } } } # 多字段查询 GET es_biz_trade_product/_search { "query": { "multi_match": { "query": "10", "fields": ["id","name"] } } } # 词条匹配(精确查找),terms可以匹配多个 terms:{ "original_price": ["100","50"] } GET es_biz_trade_product/_search { "query": { "term": { "original_price": "100" } } } # 结果过滤,只要 name 字段 GET es_biz_trade_product/_search { "query": { "terms": { "original_price": ["100"] } }, "_source": "name" } # 结果过滤,不带 current_price 字段 GET es_biz_trade_product/_search { "query": { "terms": { "original_price": ["100"] } }, "_source": { "excludes": "current_price" } } # 结果过滤,只要 id, name 字段 GET es_biz_trade_product/_search { "query": { "terms": { "original_price": [ "100" ] } }, "_source": { "includes": ["id", "name"] } }

分页查询 GET es_biz_trade_product/_search { "from":3, "size": 3 } # 排序查询 GET es_biz_trade_product/_search { "sort": [ { "id": { "order": "desc" } } ] } # 整体匹配,不分词 GET es_biz_trade_product/_search { "query": { "match_phrase": { "name": "章三" } } } # 分词后匹配 GET es_biz_trade_product/_search { "query": { "match": { "name": "章三 里斯" } } } # must / bool 两个条件都为true GET es_biz_trade_product/_search { "query": { "bool": { "must": [ { "match": { "name": "里斯" } }, { "match": { "name": "9月" } } ] } } } # should / bool 两个条件有一个为true就行 GET es_biz_trade_product/_search { "query": { "bool": { "should": [ { "match": { "name": "里斯" } }, { "match": { "name": "9月" } } ] } } } # must_not / bool 两个条件都不为true就行 GET es_biz_trade_product/_search { "query": { "bool": { "must_not": [ { "match": { "name": "里斯" } }, { "match": { "name": "9月" } } ] } } }

must_not / must 组合 GET es_biz_trade_product/_search { "query": { "bool": { "must": [ { "match": { "name": "章三" } } ], "must_not": [ { "match": { "name": "里斯" } }, { "match": { "name": "9月" } } ] } } } # filter 过滤器,过滤大于等于和小于等于 GET es_biz_trade_product/_search { "query": { "bool": { "must": { "match_all": { } }, "filter": [ { "range": { "original_price": { "gte": 50, "lte": 150 } } } ] } } } # group 聚合, 按current_price来聚合,size=0为不显示搜索匹配,只显示分组统计结果 GET es_biz_trade_product/_search { "size": 0, "aggs": { "group_by_current_price": { "terms": { "field": "current_price" } } } } # group 聚合, 按current_price来聚合,再组合original_price算AVG GET es_biz_trade_product/_search { "size": 0, "aggs": { "group_by_current_price": { "terms": { "field": "current_price" }, "aggs": { "average_original_price": { "avg": { "field": "original_price" } } } } } }

group 聚合, 按ranges来聚合,并且有分组数量、求平均值 GET es_biz_trade_product/_search { "size": 0, "aggs": { "group_by_current_price": { "range": { "field": "current_price", "ranges": [ { "from": 0, "to": 50 }, { "from": 50, "to": 100 }, { "from": 100, "to":150 }, { "from": 150, "to":200 }, { "from": 200, "to":300 } ] }, "aggs": { "group_by_original_price": { "terms": { "field": "original_price" }, "aggs": { "average_original_price": { "avg": { "field": "original_price" } } } } } } } }

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )