首页 > 其他分享 >ES查询

ES查询

时间:2024-02-07 15:23:28浏览次数:34  
标签:search GET tablename 查询 select query id ES

ES查询语句

select * from tablename
GET tablename/_search
{"query": {
  "match_all": {}
}}
select * from tablename where e_id = "XXX"
GET tablename/_search
{"query": {"term": {
  "eId": {
    "value": "XXX"
  }
}}}

'#逻辑运算符,布尔运算符[NOT,AND,OR]
'#bool包裹,相当于括号
'#NOT

select * from tablename where e_id != "XXX"
GET tablename/_search
{
  "query": {"bool": {"must_not": [
    {"term": {
      "eId": {
        "value": "XXX"
      }
    }}
  ]}}
}
'# IN&AND
select * from tablename where e_id in ("XXX", "YYY") and state = 2
GET tablename/_search
{
  "query": {
    "bool": {"must": [
      {"terms": {
    "eId": [
      "XXX",
      ""
    ]
  }},{"term": {
    "state": {
      "value": "2"
    }
  }}
    ]}
  }
}

ORDER BY

select * from tablename order by create_time desc
GET tablename/_search
{
  "sort": [
    {
      "createTime": {
        "order": "desc"
      }
    }
  ]
}

'# 查询指定字段

select comapnyName, source from tablename
GET tablename/_search
{
  "_source": {"includes": ["companyName", "source"]}
}

'# LIMIT

select * from tablename limit 100
GET tablename/_search
{
  "size": 100
  , "from": 1
}

'# OR

select * from tablename where e_id in ("A","B") or (e_id = C and y_id = c)
GET tablename/_search
{"query": {
  "bool": {"should": [
    {"terms": {
      "eId": [
        "A",
      "B"
      ]
    }},{"bool": {"must": [
      {"term": {
        "eId": {
          "value": "C"
        }
      }},{"term": {
        "yList.yId.keyword": {
          "value": "c"
        }
      }}
    ]}}
  ]}
}}

'# SUM

select SUM(e_amount) from tablename
GET tablename/_search
{
  "size": 0,"aggs": {
    "win": {
      "sum": {
        "field": "eAmount"
      }
    }
  }
}

'# NULL

select * from tablename where f_time is not Null
GET tablename/_search
{"query": {"exists":{"field": "fTime"}}}

'# 查看所有索引:

show databases
GET _cat/indices

'# GROUP BY

select SUM(e_amount) from tablename group by d_name
GET tablename/_search
{
  "size": 0, "query": {"range": {
    "eTime": {
      "gte": "2021-07-01 00:00",
      "lte": "2021-07-31 23:59"
    }
  }},
  "aggs": {
    "dName": {
      "terms": {
        "field": "dName",
        "size": 10
      },
      "aggs": {
        "d_win": {
          "sum": {
            "field": "eAmount"
          }
        }
      }
    }
  }
}


模糊搜索,查询前缀
SELECT * FROM tablename WHERE id like '12315341%';
{ "query": { "prefix": { "id": "12315341" } } }

五.更新数据
'# 更新指定字段

UPDATE tablenameSET uId = null WHERE id in ("A","B")
POST tablename/_update_by_query
{
    "query": {
        "terms": {
            "_id": [
                "A",
                "B"            ]
        }
    },
    "script": {
        "inline": "ctx._source.userId=null"
    }
}

SQL转ES查询DSL语句:http://www.ischoolbar.com/EsParser/

六.工具
(1)Kibana:默认端口为5601

(2)接口请求工具postman:
URL(表路径):http://192.168.x.x:9200/_index/_type
Content-Type:application/json
两种方式:指定行(id),使用query
新增
PUT+URL
POST+URL/_id(id存在即编辑)
删除
POST+URL/_delete_by_query
DELETE+URL/_id
修改
POST+URL/_update_by_query
POST+URL/_update
POST+URL/_id(存在的id)
查询
GET+URL/_search
GET+URL/_id

标签:search,GET,tablename,查询,select,query,id,ES
From: https://www.cnblogs.com/dapangzhuyaobianfeizhu/p/18010952

相关文章

  • uniapp 实践二 uni-id-pages
    导入用到以上的组件。发现没办法弄到分包但是uni-id-pages这个可以弄到分包里面作者的建议:如果改动不大,那么每次更新uni-id-pages时,在HBuilderX的对比界面对比一下就好如果改动较大,建议复制一套前端页面到自己工程的pages目录下,pages.json里只引用根目录pages下的页面,不引......
  • kubernetes---namespace(命名空间)
    1.查看namespace[root@k8s-master1~]#kubectlgetnamespaces#namespaces可以简写namespace或nsNAMESTATUSAGEdefaultActive130m #所有未指定Namespace的对象都会被默认分配在default命名空间kube-node-leaseActive130m kube-publ......
  • kubernetes集群核心概念---pod
    1.pod介绍参考链接:https://kubernetes.io/zh/docs/concepts/workloads/pods/1.1.查看pod[root@centos~]#kubectlgetpod#pod或pods都可以,不指定namespace,默认是名为default的namespace [root@centos~]#kubectlgetpod-nkube-system1.2.pod的yaml资源清单格式......
  • Oracle 19c enterprise manager express username password
    *[Oracle19centerprisemanagerexpressusernamepassword-Search](https://cn.bing.com/search?q=Oracle+19c+enterprise+manager+express+username+password&qs=n&form=QBRE&sp=-1&lq=0&pq=oracle+19c+enterprise+manager+express+username+passw......
  • ES的安装
    1.Elasticsearch的安装环境安装步骤:1.需要安装JAVA环境,是因为ElasticSearch是用java开发的。2.安装ES和KibanaES的图形化界面是Kibana。注意安装时,ES和Kibana的版本一定要匹配,最好安装相同的版本号。3.安装ES的分词库IK注意安装时,ES和IK分词器的版本一定要匹......
  • C++ CryptoPP使用AES加解密
    Crypto++(CryptoPP)是一个用于密码学和加密的C++库。它是一个开源项目,提供了大量的密码学算法和功能,包括对称加密、非对称加密、哈希函数、消息认证码(MAC)、数字签名等。Crypto++的目标是提供高性能和可靠的密码学工具,以满足软件开发中对安全性的需求。高级加密标准(Advance......
  • offline 2 online | 重要性采样,把 offline + online 数据化为 on-policy samples
    论文标题:Offline-to-OnlineReinforcementLearningviaBalancedReplayandPessimisticQ-EnsembleCoRL2021,4个weakaccept。pdf:https://arxiv.org/pdf/2107.00591.pdfhtml:https://ar5iv.labs.arxiv.org/html/2107.00591openreview:https://openreview.net/forum?id=......
  • 读论文-基于会话的推荐系统综述(A survey on session-based recommender systems)
    前言今天读的论文是一篇于2021年发表于"ACMComputingSurveys(CSUR)"的论文,文章写到,推荐系统在信息过载时代和数字化经济中非常重要。基于会话的推荐系统(SBRSs)是新的推荐系统范式,不同于其他模型化长期静态用户偏好的推荐系统,SBRSs专注于捕捉短期动态用户偏好。尽管SBRSs已被深......
  • kubernetes集群中一些常用的资源
    Pod(容器组):Pod是k8s中最小的可部署单元,它是一个或多个容器的集合,共享网络和存储资源,并在同一主机上运行。Pod通常包含一个主应用程序容器和辅助容器(如sidecar容器)。Deployment(部署):Deployment用于定义Pod的声明性配置,并支持滚动升级和回滚。它可以确保指定数量的Pod副本正在运行,......
  • pandas.Series.map() 与 pandas.Series.apply() 的区别!
    pandas.Series.map()与pandas.Series.apply()的区别!输出多列要用apply!输入单列输出单列map,apply输出多列输入多列applypandas.Series.map()和pandas.Series.apply()都是Pandas库中的方法,用于对Series中的每个元素进行操作。但是,它们在使用和功能上有一些区别¹²⁴......