zoukankan      html  css  js  c++  java
  • elasticsearch查询

    下载数据文档 accounts.sjon

    使用_bulk将数据索引到es集群blank索引中

    curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_bulk?pretty&refresh" --data-binary "@accounts.json"
    curl "localhost:9200/_cat/indices?v"

    查询所有

    get bank/_search
    {
        "query": {
            "match_all": {}
        }
    }

    指定字段查询

    get bank/_search
    {
        "query": {
            "match": {
                "email": "hattiebond@netagy.com"
            }
        }
    }

    范围查询

    get bank/_search
    {
        "query": {
            "range": {
                "age": {
                    "gte": 20,
                    "lte": 30
                }
            }
        }
    }

    多条件复合查询

    bool 里面的 都是一些 条件 ,must 必须瞒足,should 只要要满足 minimum_should_match 个 条件是ture ,filter 只是过滤 不计入评分

    get bank/_search
    {
        "query": {
            "bool": {
                "must": [
                    {"match": {"gender": "M"}}
                ],
                "should": [
                    {"match": {"city": "Orick"}},
                    {"match": {"city": "Brogan"}}
                ],
                "minimum_should_match": 1
            }
        }
    }
    GET /bank/_search
    {
      "query": {
        "bool": {
          "must": { "match_all": {} },
          "filter": {
            "range": {
              "balance": {
                "gte": 20000,
                "lte": 30000
              }
            }
          }
        }
      }
    }

    分组查询

    {
        "size": 0,
        "aggs": {
            "group_by_state": {
                "terms": {
                    "field": "state.keyword"
                }
            }
        }
    }

    聚合

    get bank/_search
    {
        "size": 0,
        "aggs": {
            "group_by_state": {
                "terms": {
                    "field": "state.keyword",
                    "order": {
                        "average_balance": "desc"
                    }
                },
                "aggs": {
                    "average_balance": {
                        "avg": {
                            "field": "balance"
                        }
                    }
                }
            }
        }
    }
  • 相关阅读:
    MySQL-安装mysql8
    MySQL-Prometheus
    MySQL-sysbench
    MySQL-客户端登录问题
    学习进度第十六周
    学习进度第十五周
    寻找最长单词链
    用户体验评价
    学习进度第十四周
    找水王问题
  • 原文地址:https://www.cnblogs.com/sellsa/p/12795869.html
Copyright © 2011-2022 走看看