elasticsearch常用命令总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bowei026/article/details/89037108

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

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

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

列出索引user的所有表结构
curl -XGET http://localhost:9200/user/_mapping?pretty

列出索引user中log表的结构
curl -XGET http://localhost:9200/user/log/_mapping?pretty

查找:
查找索引user中log表的url字段的值为http://www.test.com的文档(记录)

curl -XGET 'http://localhost:9200/user/log/_search?pretty' -d '{
    "query" : {
        "term" : { "url" : "http://www.test.com" }
    }
}'

查找索引user中log表的url字段的值为http://www.test.com的文档(记录),并按create_time降序输出

curl -XPOST 'http://localhost:9200/user/log/_search?pretty' -d '{
    "query" : {
        "term" : { "url" : "http://www.test.com" }
    },"sort" : [{ "create_time" : {"order" : "desc"}} ]
}'

查找索引user中log表的url字段的值为http://www.test.com的文档(记录),并输出前20个

curl -XPOST 'http://localhost:9200/user/log/_search?pretty' -d '{
    "query" : {
        "term" : { "url" : "http://www.test.com" }
    },
    "from":0,
    "size":20
}'

查找索引user中log表的url字段的值是以http://www.test.com开头的文档(记录)

curl -XPOST 'http://localhost:9200/user/log/_search?pretty' -d '{
  "query": {
    "prefix": {
      "url": {
        "value": "http://www.test.com"
      }
    }
  }
}'

查找索引user中log表的url字段的值是以http://www.test.com开头的文档(记录),输出到1.txt文件中

curl -XPOST 'http://localhost:9200/user/log/_search?pretty' -d '{
  "query": {
    "prefix": {
      "url": {
        "value": "http://www.test.com"
      }
    }
  }
}' > 1.txt


使用通配符做查找条件

curl -XPOST 'http://localhost:9200/user/log/_search?pretty' -d '{
    "query":{
        "bool":{
            "must":[
                {
                    "wildcard":{
                        "url":"http://www.test.com?id=*"
                    }
                }
            ]
        }
    },
    "from":0,
    "size":70
    , "sort" : [{ "create_time" : {"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
}

查找ip为空的文档(记录)

curl -XPOST 'http://localhost:9200/user/log/_search?pretty' -d '{
  "query": {
    "bool": {
      "must_not": {
        "exists": {
          "field": "ip"
        }
      }
    }
  },
    "from":0,
    "size":20
}'

查找ip不为空的文档(记录)

curl -XPOST 'http://localhost:9200/user/log/_search?pretty' -d '{
  "query": {
    "bool": {
      "must": {
        "exists": {
          "field": "字段名"
        }
      }
    }
  }
}'

猜你喜欢

转载自blog.csdn.net/bowei026/article/details/89037108
今日推荐