赞
踩
目录
1. 查询出包含 log_geo 的数据 “wildcard”: { “message”: “log_geo” }
log_geo 前面有*表示搜索以log_geo结尾的数据
log_geo后面有* 表示搜以log_geo开始的数据
log_geo前后都有*就是通用匹配包含log_geo的记录
- “wildcard”:
- {
- “message”: “log_geo”
- }
- “range”: {
- “@timestamp”: {
- “gt”: “2018-02-08T07:00:00.056000000+00:00”,
- ”lt”: “2018-02-08T08:00:00.056000000+00:00”
- }
- }
#注意 时区减去8小时
3.1 match 包含provider 的数据
- {
- “match”:
- {
- “message”: “type:provider”
- }
- }
3.2 must_not 类似于 must 做排除使用
- “must_not”: {
- “match”: {
- “message”: “dateTime:2018-02-08 15:59”
- }
- }
但在es中使用should查询必须要和must一起使用才可以,相当于must[should A,should B]
,中文解释就好比是满足A或者是B条件的数据
布尔查询是一个复合查询,由各个bool类型的子查询组成。
must :返回文档必须满足该条件,且提供分数
filter :返回文档必须满足该条件,但是不需要提供分数
should :返回文档可以满足0个或多个条件,且提供分数
must_not : 返回文档必须不满足条件,但是不需要提供分数
查询语句 1,2,3可以组合,也可以单独使用,查询语句如果得不到想要的结果应该是ES的分词导致的,组合起来的语句如下:
- {
- "query": {
- "bool": {
- "must": [
- { "range": { "@timestamp": { "gt": "2018-02-08T07:00:00.056000000+00:00","lt": "2018-02-08T08:00:00.056000000+00:00" } } }
- ,
- { "wildcard": { "message": "*cp_geo*" } }
- ,
- { "match": { "message": "*type:platform*" } }
- ],
- "must_not": { "match": { "message": "*deviceTypeCode:DTout00000000*" } },
- "should": []
- }
- },
- "from": 0,
- "size": 50,
- "sort": { "@timestamp": "desc" },
- "aggs": {}
- }
参考原文地址:https://blog.51cto.com/u_8649447/4869008
通过_source 字段中的 include 和 exclude 来指定返回结果包含哪些字段,排除哪些字段
举例:根据关系单号,查询 es,设置_source 的 include 和 exclude
实例查询语句:
- {
- "_source":{
- "include":[
- "policyNo",
- "policyRelationNo",
- "policyStatus"
- ],
- "exclude":[
- "salesType"
- ]
- },
- "query": {
- "bool": {
- "must": [
- {
- "term": {
- "policyRelationNo": "KR01435021"
- }
- }
- ],
- "should": [],
- "must_not": []
- }
- },
- "from": 0,
- "size": 10
- }
查询效果:
- {
- "_shards": {
- "total": 5,
- "successful": 5,
- "failed": 0
- },
- "hits": {
- "total": 19,
- "max_score": 11.391884,
- "hits": [
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407038",
- "_score": 11.391884,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120319",
- "policyStatus": 11
- }
- },
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407046",
- "_score": 10.713255,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120323",
- "policyStatus": 11
- }
- },
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407044",
- "_score": 10.713255,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120322",
- "policyStatus": 11
- }
- },
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407066",
- "_score": 10.713255,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120333",
- "policyStatus": 11
- }
- },
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407058",
- "_score": 10.713255,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120329",
- "policyStatus": 11
- }
- },
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407070",
- "_score": 10.713255,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120335",
- "policyStatus": 11
- }
- },
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407056",
- "_score": 10.294733,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120328",
- "policyStatus": 11
- }
- },
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407052",
- "_score": 10.294733,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120326",
- "policyStatus": 11
- }
- },
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407062",
- "_score": 10.294733,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120331",
- "policyStatus": 11
- }
- },
- {
- "_index": "search4policy-msad-dev3_20200520000000",
- "_type": "policy-msad-dev3",
- "_id": "4407064",
- "_score": 10.294733,
- "_source": {
- "policyRelationNo": "KR01435021",
- "policyNo": "B609120332",
- "policyStatus": 11
- }
- }
- ]
- },
- "took": 5,
- "timed_out": false
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。