zoukankan      html  css  js  c++  java
  • es crul查询(一)

    C:UsersAdministrator>elasticdump --input=D:	est --output=http://localhost:9200/logs_apipki_20190102
    #查询所有索引信息
    http://localhost:9200/_cat/indices?v
    #轻量级搜索
    curl -X GET "localhost:9200/test/user/_search?q=last_name:Smith"
    
    #表达式搜索
    curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
    {
        "query" : {
            "match" : {
                "last_name" : "Smith"
            }
        }
    }
    '
    #filter实现结勾化查询
    curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
    {
        "query" : {
            "bool": {
                "must": {
                    "match" : {
                        "last_name" : "smith" 
                    }
                },
                "filter": {
                    "range" : {
                        "age" : { "gt" : 30 } 
                    }
                }
            }
        }
    }
    '
    #模糊匹配(向下匹配,并根据匹配的分数排序)
    curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
    {
        "query" : {
            "match" : {
                "about" : "rock climbing"
            }
        }
    }
    '
    #短语搜索(精准匹配)
    curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
    {
        "query" : {
            "match_phrase" : {
                "about" : "rock climbing"
            }
        }
    }
    '
    #高亮查询
    curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
    {
        "query" : {
            "match_phrase" : {
                "about" : "rock climbing"
            }
        },
        "highlight": {
            "fields" : {
                "about" : {}
            }
        }
    }
    '
    #聚合函数(类似group by)
    curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
    {
      "aggs": {
        "all_interests": {
          "terms": { "field": "interests" }
        }
      }
    }
    '
    #先根据query条件过滤,在聚合
    curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
    {
      "query": {
        "match": {
          "last_name": "smith"
        }
      },
      "aggs": {
        "all_interests": {
          "terms": {
            "field": "interests"
          }
          "aggs" : {//分级聚合各个intrests对应的平均年龄
                    "avg_age" : {
                        "avg" : { "field" : "age" }
                    }
                }
        }
      }
    }
    '
  • 相关阅读:
    centos7安装es6.4.0
    将mysql数据同步到ES6.4(全量+增量)
    c#基于supersocket的简单websocket服务端收发消息实现
    c#log4net简单好用的配置
    MongoDB安装配置教程
    IntelliJ IDEA 中创建maven项目
    VMware Workstation 的安装和使用
    Redis使用场景
    Redis 下载安装
    MySQL--启动和关闭MySQL服务
  • 原文地址:https://www.cnblogs.com/guozhigang/p/10775671.html
Copyright © 2011-2022 走看看