zoukankan      html  css  js  c++  java
  • elastic search查询

    分类查询topN

    PUT /test
    {
        "mappings" : {
          "properties" : {
            "firstName" : {
              "type" : "text"
            },
            "lastName" : {
              "type" : "text"
            },
            "mobile" : {
              "type" : "text"
            },
            "htime":{
              "type": "date",
              "format": "yyyy-MM-dd HH:mm:ss"
            },
            "ltime":{
              "type": "long"
            }
          }
        }
    }

    // 插入数据

    PUT /test/_doc/1 ... 3
    {
    "firstName":"m3",
    "lastName":"w3",
    "mobile":"18258211286",
    "htime":"2021-08-11 12:12:12",
    "ltime":1475251200000
    }

    分类查询

    GET test/_search
    {
      "size": 3,
      "query": {
        "match_all": {}
      },
      "aggs": {
        "top_tags": {
          "terms": {
            "field": "htime",
            "size": 3
          },
          "aggs": {
            "most_bytes": {
              "top_hits": {
                "sort": [
                  {
                    "ltime": {
                      "order": "desc"
                    }
                  }
                ],
                "_source": {
                  "includes": [
                    "htime",
                    "ltime",
                    "lastName",
                    "firstName"
                  ]
                },
                "size": 2
              }
            }
          }
        }
      }
    }

    结果

    {
      "took" : 1,
      "timed_out" : false,
      "_shards" : {
        "total" : 1,
        "successful" : 1,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : {
          "value" : 3,
          "relation" : "eq"
        },
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "firstName" : "m",
              "lastName" : "w",
              "ltime" : 1475251200000,
              "lmonthDay" : "10-01",
              "monthDay" : "08-09",
              "mobile" : "18258211286",
              "htime" : "2021-08-09 12:12:12"
            }
          },
          {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "2",
            "_score" : 1.0,
            "_source" : {
              "firstName" : "m1",
              "lastName" : "w1",
              "mobile" : "18258211286",
              "htime" : "2021-08-10 12:12:12",
              "ltime" : 1475251200000
            }
          },
          {
            "_index" : "test",
            "_type" : "_doc",
            "_id" : "3",
            "_score" : 1.0,
            "_source" : {
              "firstName" : "m3",
              "lastName" : "w3",
              "mobile" : "18258211286",
              "htime" : "2021-08-11 12:12:12",
              "ltime" : 1475251200000
            }
          }
        ]
      },
      "aggregations" : {
        "top_tags" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 0,
          "buckets" : [
            {
              "key" : 1628511132000,
              "key_as_string" : "2021-08-09 12:12:12",
              "doc_count" : 1,
              "most_bytes" : {
                "hits" : {
                  "total" : {
                    "value" : 1,
                    "relation" : "eq"
                  },
                  "max_score" : null,
                  "hits" : [
                    {
                      "_index" : "test",
                      "_type" : "_doc",
                      "_id" : "1",
                      "_score" : null,
                      "_source" : {
                        "firstName" : "m",
                        "lastName" : "w",
                        "ltime" : 1475251200000,
                        "htime" : "2021-08-09 12:12:12"
                      },
                      "sort" : [
                        1475251200000
                      ]
                    }
                  ]
                }
              }
            },
            {
              "key" : 1628597532000,
              "key_as_string" : "2021-08-10 12:12:12",
              "doc_count" : 1,
              "most_bytes" : {
                "hits" : {
                  "total" : {
                    "value" : 1,
                    "relation" : "eq"
                  },
                  "max_score" : null,
                  "hits" : [
                    {
                      "_index" : "test",
                      "_type" : "_doc",
                      "_id" : "2",
                      "_score" : null,
                      "_source" : {
                        "firstName" : "m1",
                        "lastName" : "w1",
                        "ltime" : 1475251200000,
                        "htime" : "2021-08-10 12:12:12"
                      },
                      "sort" : [
                        1475251200000
                      ]
                    }
                  ]
                }
              }
            },
            {
              "key" : 1628683932000,
              "key_as_string" : "2021-08-11 12:12:12",
              "doc_count" : 1,
              "most_bytes" : {
                "hits" : {
                  "total" : {
                    "value" : 1,
                    "relation" : "eq"
                  },
                  "max_score" : null,
                  "hits" : [
                    {
                      "_index" : "test",
                      "_type" : "_doc",
                      "_id" : "3",
                      "_score" : null,
                      "_source" : {
                        "firstName" : "m3",
                        "lastName" : "w3",
                        "ltime" : 1475251200000,
                        "htime" : "2021-08-11 12:12:12"
                      },
                      "sort" : [
                        1475251200000
                      ]
                    }
                  ]
                }
              }
            }
          ]
        }
      }
  • 相关阅读:
    JS 学习笔记
    Input控件只允许输入指定字符
    NPOI导出excel使用
    combobox级联检索下拉选择框
    vue父组件调用子组件方法
    EasyUI设置Layout自适应浏览器宽度和高度
    EasyUI创建选项卡并判断是否打开
    Jquery+ajaxfileupload上传文件
    Jquery禁用网页右键菜单
    c#删除指定文件夹中今天之前的文件
  • 原文地址:https://www.cnblogs.com/beaconSky/p/15546224.html
Copyright © 2011-2022 走看看