es操作指令大全(kibala)

./elasticsearch -d  后台启动
ps aux|grep elasticsearch可以查看是否启动


 重新启用分配路由


  删除某个index

DELETE  /index

创建一个索引

PUT  xxxindex

 查看索引的设置

GET  unitindex/_settings

PUT /_cluster/settings
{
    "transient" : {
        "cluster.routing.allocation.enable" : "all"
    }
}

查询指定数量的信息,如果不指定起始值,默认只会显示10条 


GET 索引/_search
{
  "from":0,
  "size":100,
  "query" : {
    "bool" : {
      "must" : [
        {
          "match_all" : {
          }
        }
      ]
    }
  }
}


删除指定id的文档

DELETE  index/type/id

查询所有索引 

GET  _cat/indices?v

查询目标索引

GET   索引名/_search

查询 某个type的信息

GET  索引名/type名/_search

# 建立表结构
# index 设置为false表示不建立索引,interger和keyword表示精确查找
PUT qinqin
{
  "mappings": {
    "doc": {
      "properties": {
        "address": {
          "type": "text",
          "analyzer": "ik_max_word"
        },
        "age": {
          "type": "integer"
        },
        "shengFenZheng": {
          "type": "keyword"
        },
        "like": {
          "type": "text",
          "index": false
        }
      }
    }
  }
}





#搜索所有,并且分页
GET  vemindex/_search
{
  "from" : 0,
  "size" : 1,
  "query" : {
    "bool" : {
      "must" : [
        {
          "match_all" : {}
        }
      ]
    }
  }
}





GET  qinqin/_mapping




# 添加一个文档
PUT qinqin/doc/1
{
  "address": "潢川  付店",
  "age": 35,
  "shengFenZheng": "郑州洛阳",
  "like": "看书 看电影"
}



# 添加一个文档
PUT qinqin/doc/2
{
  "address": "潢川  红庄",
  "age": 35,
  "shengFenZheng": "郑州开封",
  "like": "看书写字"
}




# 添加一个文档
PUT qinqin/doc/3
{
  "address": "潢川  马庄",
  "age": 36,
  "shengFenZheng": "荥阳开封",
  "like": "看书象棋 "
}





# 添加一个文档
PUT qinqin/doc/4
{
  "address": "光山马庄",
  "age": 37,
  "shengFenZheng": "平顶山开封",
  "like": "听歌象棋 "
}





# 查询id为1的文档
GET qinqin/doc/1 



#  查询所有

GET qinqin/doc/_search
{
    "query":{
        "match_all":{}
    }
}





#  分页
GET qinqin/doc/_search
{
    "from":0,
    "size":100,
    "query":{
        "term":{
            "age": 3
        }
    }
}





# 按关键字降序排列
GET qinqin/doc/_search
{
    "from":0,
    "size":100,
    "query":{
       "match_all":{}
    },
    "sort":[
        {"age":{"order":"desc"}}
    ]
}





# integer  精确匹配
GET  qinqin/_search
{
  "query":{
     "match": {
       "age": 35
     }
  }
}





# keyword 精确匹配
GET  qinqin/_search
{
  "query":{
     "match": {
       "shengFenZheng": "郑州开封"
     }
  }
}





# index=false 表示不建立索引
GET  qinqin/_search
{
  "query":{
     "match": {
       "like": "听歌象棋"
     }
  }
}





# 全文检索
GET  qinqin/_search
{
  "query":{
     "match": {
       "address": "潢川张庄"
     }
  }
}




# gt:大于,gte:大于等于,lt:小于,lte:小于等于
# 查询 35<=age<=36 所有文档
GET  qinqin/_search
{
  "query":{
     "range": {
        "age": {
           "gte": 35,
           "lte": 36
      }
    }
  }
}



# 字段平均计算
GET  qinqin/_search
{
  "aggs": {
    "avg_age": {
      "avg": {
        "field": "age"
      }
    }
  }
}


# 字段分组聚合,统计总和
GET  qinqin/_search
{
  "aggs": {
     "avg_age": {
        "terms": {
             "field": "age"
         }
      },
      "sum_age": {
            "sum": {
                   "field": "age"
             }
       }
    
  }
}





# 查某个字段的最小值最大值
GET  qinqin/_search
{
  "aggs": {
     "min_age": {
         "min": {
             "field": "age"
                }
      },
      "max_age": {
        "max": {
              "field": "age"
               }
      }
   }
}



# 过滤查询,查询年龄大于等于35
GET  qinqin/_search
{
  "aggs":{
      "recent_sales": {
            "filter": {
                "range": {
                      "age": {
                          "from": 35
                       }
                 }
             }
      }
  }
}


# 统计某个字段去重后的数量
GET /qinqin/doc/_search
{
  "size": 0,
  "aggs": {
             "distinct_ages": {
                 "cardinality": {
                        "field": "age"
                  }
               }
          }
}



# 按照某个字段进行聚合分组
GET /qinqin/doc/_search
{
  "size": 0,
  "aggs": {
             "distinct_ages": {
                 "terms": {
                        "field": "age"
                  }
               }
          }
}




#聚合分组后,只显示size个分桶
GET /qinqin/doc/_search
{


  "aggs": {
             "distinct_ages": {
                 "terms": {
                        "field": "age",
                        "size": 2  
                  }

               }
          }
}




#聚合分组后,并且按照年龄降序返回每组中前10个
# terms中size是返回几桶
#top_hits中的size代表每桶中取几个
GET /qinqin/doc/_search
{


  "aggs": {
             "distinct_ages": {
                 "terms": {
                        "field": "age",
                        "size": 2  
                  },
                  "aggs": {
                         "rated": {
                                   "top_hits": {
                                           "sort": [{
                                               "age": {"order": "desc"}
                                            }], 
                                           "size": 10
                                    }
                          }
                   }

             }
   }
}






#  数据直方图
GET /qinqin/doc/_search
{
  "size": 0,
  "aggs": {
     "ages": {
          "date_histogram": {
                 "field": "age",
                 "interval":2
           }
       }
   }
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值