elasticsearch 常用命令

检查健康状态
curl 'localhost:9200/_cat/health?v'

获得集群中的节点列表
curl 'localhost:9200/_cat/nodes?v'

列出所有的索引
curl -XGET http://localhost:9200/_cat/indices?v

curl -XGET http://localhost:9200/track/_mapping?pretty

curl -XGET http://localhost:9200/track/crm_log/_mapping?pretty

精确查询

curl -XGET 'http://localhost:9200/track/crm_log/_search?pretty' -d '{
    "query" : {
        "term" : { "url" : "https://infosalons.com/vscenter/visitor/confirmation.aspx?id=123&e=abc@def.com&exh=abcd" }
    }
}'


curl -XPOST 'http://localhost:9200/track/crm_log/_search?pretty' -d '{
    "query" : {
        "term" : { "domain" : "ali.infosalons.com.cn" }
    },"sort" : [{ "createTime" : {"order" : "desc"}} ]
}'


curl -XPOST 'http://localhost:9200/track/crm_log/_search?pretty' -d '{
    "query" : {
        "term" : { "domain" : "ali.infosalons.com.cn" }
    },
    "from":0,
    "size":20
}'

知道前缀的查询
curl -XPOST 'http://localhost:9200/track/crm_log/_search?pretty' -d '{
  "query": {
    "prefix": {
      "url": {
        "value": "https://ali.infosalons.com.cn/vscenter/visitor/confirmation.aspx?id="
      }
    }
  }
}'

查询结果输出到文档

curl -XPOST 'http://localhost:9200/track/crm_log/_search?pretty' -d '{
  "query": {
    "prefix": {
      "url": {
        "value": "https://ali.infosalons.com.cn/vscenter/visitor/confirmation.aspx?id="
      }
    }
  }
}' > 1.txt

模糊查询,支持通配符,如*

curl -XPOST 'http://localhost:9200/track/crm_log/_search?pretty' -d '{
    "query":{
        "bool":{
            "must":[
                {
                    "wildcard":{
                        "url":"https://ali.infosalons.com.cn/vscenter/visitor/confirmation.aspx?id=*"
                    }
                }
            ]
        }
    },
    "from":0,
    "size":70
    , "sort" : [{ "createTime" : {"order" : "asc"}} ]
}' > 2.txt

 

组合多条件查询

{
    "query": {
        "bool": {
            "minimum_should_match": 1,
            "must": [{
                    "match": {
                        "XB": "2 "
                    }
                },
                {
                    "wildcard": {
                        "XM": "王*"
                    }
                }
            ],
            "should": [{
                "range": {
                    "CSRQ": {
                        "gte": "2010-09-01",
                        "lte": "2014-09-01"
                    }
                }
            }]
        }
    },
    "from": 0,
    "size": 10
}

本文内容到此结束,更多内容可关注公众号

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值