美文网首页
es简单查询

es简单查询

作者: 高峥 | 来源:发表于2022-01-04 17:03 被阅读0次

时间格式化

"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd",

GET log-lingxi_backend*/_search
{
  "aggs": {
    "aggs_num": {
      "adjacency_matrix": {
        "filters": {
          "First_five_minutes": {
            "bool": {
              "must": [
                {
                  "range": {
                    "timestamp": {
                      "gte": "now-1d"
                    }
                  }
                }
              ]
            }
          },
          "First_ten_minutes": {
            "bool": {
              "must": [
                {
                  "range": {
                    "timestamp": {
                      "gte": "now-5m"
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "aggs": {
        "aggs_level": {
          "terms": {
            "field": "levelname.keyword"
          }
        }
      }
    }
  },
  "size": 0,
  "_source": ["timestamp","levelname"]
}


GET log-lingxi_back*/_mapping
  
GET log-lingxi_backend*/_search
{
    "query": {
      "prefix": {
        "msg.keyword": {
          "value": "用"
        }
      }
      
    },
    "_source": ["msg"]
  
}


GET log-lingxi-merchant-api*/_search
{
    "aggs": {
          "time_range": {
                "range": {
                    "field": "timestamp",
                    "ranges": [
                        {
                            "from": "now-60d",
                            "key": "now-60d"
                        },
                        {
                            "from": "now-30m",
                            "key": "now-30m"
                        },
                        {
                            "from": "now-15m",
                            "key": "now-15m"
                        },
                        {
                            "from": "now-5m",
                            "key": "now-5m"
                        }
                    ]
                },
                "aggs": {
                    "aggs_level": {
                        "terms": {
                            "field": "levelname.keyword"
                        }
                    }
                }
            }
        },
        "size": 0
  
}


GET log-lingxi-merchant-api*/_search
{
  "aggs": {
    "s_type": {
      "terms": {
        "field": "type.keyword"
        
      },
      "aggs": {
          "time_range": {
                "range": {
                    "field": "timestamp",
                    "ranges": [
                        {
                            "from": "now-60d",
                            "key": "now-60d"
                        },
                        {
                            "from": "now-30m",
                            "key": "now-30m"
                        },
                        {
                            "from": "now-15m",
                            "key": "now-15m"
                        },
                        {
                            "from": "now-5m",
                            "key": "now-5m"
                        }
                    ]
                },
                "aggs": {
                    "aggs_level": {
                        "terms": {
                            "field": "levelname.keyword"
                        }
                    }
                }
            }
        }
    }
    
  },
        "size": 0
}

GET log-lingxi_backend*/_search
{
  "_source": [
    "name",
    "msg",
    "type",
    "levelname",
    "message",
    "log",
    "timestamp",
    "sql"
  ],
  "from": 0,
  "query": {
    "bool": {
      "must": [
        {"range": {
          "timestamp":{
            "gt": "2021-12-26T11:24:90"
          }
        }}
      ]
          
    }
  },
  "size": 2,
  "sort": {
    "timestamp": {
      "order": "desc"
    }
  },
  "track_total_hits": "true"
}


GET log-lingxi-merchant-api*/_search
{
  "_source": [
    "name",
    "msg",
    "type",
    "levelname",
    "message",
    "log",
    "timestamp",
    "sql"
  ],
  "from": 0,
  "query": {
    "bool": {
      "must": [
        {"range": {
          "timestamp":{
            "gt": "2021-12-27T05:29:37.531Z"
            
          }
        }}
      ]
          
    }
  },
  
  "sort": {
    "timestamp": {
      "order": "desc"
    }
  },
  "track_total_hits": "true"
}


GET log-lingxi-merchant-api*/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "timestamp": {
              "gt": "2021-12-27T05:29:37.531Z"
            }
          }
        },
        {"term": {
          "type": {
            "value": "system"
          }
        }}
      ]
    }
  },
  "track_total_hits": "true",
  "aggs": {
      "request_histogram": {
         "date_histogram": {
            "field": "timestamp",
            "fixed_interval": "5m", 
            "format": "yyyy-MM-dd HH:mm:SS" 
         }
      }
   },
   "size": 0
 
}


GET log-lingxi-merchant-api-2021.12.20/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "type": "service"
          }
        },
        {
          "range": {
            "timestamp":{
              "gte": "2021-11-25 20:10:10", 
              "lt": "now",
              "format": "yyyy-MM-dd HH:mm:SS||yyyy-MM-dd"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "project": {
      "terms": {
        "field": "project.keyword",
        "order": {
          "total_record": "desc"
        }
      },
      "aggs": {
        "total_record": {
          "value_count": {
            "field": "levelname.keyword"
          }
        },
        "error": {
          "filter": {
            "term": {
              "levelname.keyword": "ERROR"
            }
          }
        },
        "level_percentage": {
          "bucket_script": {
            "buckets_path": {
              "E": "error > _count",
              "T": "total_record"
            },
            "format": "#.##",
            "script": "params.E /params.T * 100"
          }
        },
        "rate_bucket_sort": {
          "bucket_sort": {
            "sort": [
              {
                "level_percentage.value": {
                  "order": "desc"
                }
              }
            ]
          }
        }
      }
    }
  },
  "size": 0
}

GET log-*/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "type": "service"
          }
        },
        {
          "range": {
            "timestamp": {
              "gte": "2021-12-23",
              "lt": "now",
              "format": "yyyy-MM-dd HH:mm:SS||yyyy-MM-dd"
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "error": {
      "filter": {
        "term": {
          "levelname.keyword": "ERROR"
        }
      },
      "aggs": {
        "request_histogram": {
          "date_histogram": {
            "field": "timestamp",
            "fixed_interval": "2d",
            "format": "yyyy-MM-dd HH:mm:SS"
          }
        }
      }
    }
    ,
    "total_record": {
      "date_histogram": {
        "field": "timestamp",
        "fixed_interval": "2d",
        "format": "yyyy-MM-dd HH:mm:SS"
      }
    }
  },
  "track_total_hits": "true",
  "size": 0
}


GET log-lingxi-merchant-api*/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "type": "service"
          }
        },
        {
          "range": {
            "timestamp": {
              "gte": "2021-12-23",
              "lt": "now",
              "format": "yyyy-MM-dd HH:mm:SS||yyyy-MM-dd"
            }
          }
        }
      ]
    }
  },

  "aggs": {
    "request_histogram": {
      "date_histogram": {
        "field": "timestamp",
        "fixed_interval": "2d",
        "format": "yyyy-MM-dd HH:mm:SS"
      },
      "aggs": {
        "error": {
          "filter": {
            "term": {
              "levelname.keyword": "ERROR"
            }
          }
        },
        "level_percentage": {
          "bucket_script": {
            "buckets_path": {
              "E": "error > _count",
              "T": "_count"
            },
            "format": "#.##",
            "script": "(1-params.E /params.T) * 100"
          }
        }
      }
    }
  }
    ,
  "track_total_hits": "true",
  "size": 0
}


相关文章

  • es简单查询

    ES即简单又复杂,你可以快速的实现全文检索,又需要了解复杂的REST API。本篇就通过一些简单的搜索命令,帮助你...

  • es简单查询

    时间格式化 "format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd",

  • Kibana 查询语法 --- 2022-04-03

    Kibana Query Language (KQL)查询语法是Kibana为了简化ES查询设计的一套简单查询语法...

  • ElasticSearch 7.x 聚合查询

    聚合查询 |ES 的聚合查询和MyQL的聚合查询类型,ES 的聚合查询相比MySQL 要强大的多,ES提供的统计数...

  • ES 全文搜索

    ES 全文搜索 全文搜索 使用了match查询的多词查询只是简单地将生成的term查询包含在了一个bool查询中。...

  • ES简单实用DSL查询

    ES版本信息 查看所有索引 查看字段类型 创建索引 删除索引 批量(_bulk)加载数据 查询数据 查询1000条...

  • ES索引查询匹配,简单记录

    存入数据代码,以及es删除索引数据 从es里查询数据------单匹配查询

  • ElasticSearch:字段--精确查询||模糊查询

    ES数据类型 模糊查询: 精确查询:

  • es7.x(10)aggs聚合查询

    ES聚合查询流程 核心概念2.1 桶2.2 指标 ES聚合查询的语法3.1 聚合查询的size语法 指标聚合4.1...

  • es

    es种有两种查询模式,一种是像传递URL参数一样去传递查询语句,被称为简单搜索或查询字符串(query strin...

网友评论

      本文标题:es简单查询

      本文链接:https://www.haomeiwen.com/subject/kgaqcrtx.html