首页 技术 正文
技术 2022年11月9日
0 收藏 783 点赞 2,984 浏览 2249 个字

利用kibana插件对Elasticsearch查询

Elasticsearch是功能非常强大的搜索引擎,使用它的目的就是为了快速的查询到需要的数据。

查询分类:

  基本查询:使用Elasticsearch内置查询条件进行查询

  组合查询:把多个查询组合在一起进行复合查询

  过滤:查询同时,通过filter条件在不影响打分的情况下筛选数据

创建索引
PUT lagou
{
"mappings": {
"job":{
"properties": {
"title":{
"store": true,
"type": "text",
"analyzer": "ik_max_word"
},
"company_name":{
"store": true,
"type": "keyword"
},
"desc":{
"type": "text"
},
"comments":{
"type": "integer"
},
"add_time":{
"type": "date",
"format": "yyyy-MM-dd"
}
}
}
}
}

PUT lagou

POST lagou/job
{
  “title”:”python django 开发工程师”,
  “company_name”:”美团”,
  “desc”:”美团是一个在吗在吗在吗”,
  “comments”:20,
  “add_time”:”2017-4-16″
}

POST lagou/job
{
  “title”:”python 爬虫 开发工程师”,
  “company_name”:”数据冰山”,
  “desc”:”专门找数据的一家公司 python”,
  “comments”:15,
  “add_time”:”2016-4-16″
}
POST lagou/job
{
  “title”:”django 后端 开发工程师”,
  “company_name”:”百度科技有限公司”,
  “desc”:”我也不知道这里应该写一点什么东西了 python”,
  “comments”:20,
  “add_time”:”2017-4-16″
}
POST lagou/job
{
  “title”:”python GUI  开发工程师”,
  “company_name”:”熊猫”,
  “desc”:”在线视频教育python”,
  “comments”:6,
  “add_time”:”2017-4-16″
}

#match查询,

对我们的输入进行一个分词,指明一个字段,会去找这个字段有没有我们写的这个关键词,关键词不区分大小写,在做分词的时候会自动对大小写进行转换

GET lagou/_search
GET lagou/job/_search
{
"query": {
"match": {
"title": "爬取"
}
}
}

#term查询#

传递过来的关键词不会进行任何处理不会解析,text 会分词,keyword不会分词的

GET lagou/job/_search
{
"query": {
"term": {
"company_name": "百度科技有限公司"
}
}
}

#terms查询

只要关键字中有一个都会匹配出来

GET lagou/job/_search
{
"query": {
"terms": {
"title": ["django","开发","python"]
}
}
}

#控制查询的返回数量

GET lagou/_search
{
"query": {
"match": {
"title": "python"
}
},
"from": ,
"size":
}

#从哪开始,数量多少

#match——all  查询

GET lagou/job/_search
{
"query": {
"match_all": {}
}
}

#match_phrase查询#短语查询

#slop 两词之间最小的距离,query 必须都满足所有的分词的关键词

GET lagou/_search
{
"query": {
"match_phrase": {
"title": {
"query": "python django",
"slop":
}
}
}
}

#multi_match查询#

比如可以指定多个字段#比如查询title和desc这两个字段里面包含python 的关键词的文档GET lagou/job/_search     
#     ^3   指的是权重,什么比什么的权重高多少

GET lagou/_search
{
"query": {
"multi_match": {
"query": "python",
"fields": ["title","desc^3"]
}
}
}

#指定返回的字段

GET lagou/_search
{
"stored_fields": ["title"],
"query": {
"match": {
"title": "开发"
}
}
}

#通过sort把结果排序

GET lagou/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"comments": {
"order": "desc"
}
}
]
}

#范围查询#range查询

GET lagou/_search
{
"query": {
"range": {
"comments": {
"gte": ,
"lte": ,
"boost": 2.0
}
}
}
}

#range查询

GET lagou/_search
{
"query": {
"range": {
"add_time": {
"gte": "2017-04-01",
"lte": "now"
}
}
}
}

#wildcard 查询#简单的模糊查询

GET lagou/_search
{
"query": {
"wildcard": {
"title": {
"value": "pyth*n",
"boost":
}
}
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848