kibanna操作elasticsearch命令大全

创建索引
PUT /heima
 {
      "settings": {
          "number_of_shards": 3,
          "number_of_replicas": 2
        }
  }
  查看索引
  get heima
  删除索引
  delete heima
6.创建数据库表
PUT /索引库名/_doc/类型名称
{
  "properties": {
    "字段名": {
      "type": "类型",
      "index": true,
      "store": true,
      "analyzer": "分词器"
    }
  }
}

PUT heima/_doc/goods1
{
  "properties": {
    "title": {
      "type": "text",
      "analyzer": "ik_max_word"
    },
    "images": {
      "type": "keyword",
      "index": "false"
    },
    "price": {
      "type": "float"
    }
  }
}

查看数据库
get heima/_doc/goods
新增字段
POST /索引库名/类型名
{
    "key":"value"
}
post heima/_doc/goods
{
    "key":"value"
}
新增数据
POST /heima/goods/                    
{
    "title":"小米手机",
    "images":"http://image.leyou.com/12479122.jpg",
    "price":2699.00
   
}

查询数据
GET /heima/_search
{
  "query": {
    "match_all": {}
  }
}

多字段查询
GET /heima/_search
{
  "query": {
    "multi_match":{
      "query": "小米手机",
      "fields": ["title","images"]
    }
  }
}
多词条查询
GET /heima/_search
{
  "_source": {
    "includes":["title","price"] 
  },
  "query": {
    "term": {
      "price": 2699
    }
  }
}
范围查找
GET /heima/_search
{
    "query":{
        "range": {
            "price": {
                "gte":  1000.0,
                "lt":   2800.00
            }
        }
    }
}
模糊查找
GET /heima/_search
{
  "query": {
    "fuzzy": {
        "title": {
            "value":"appla",
            "fuzziness":1  
        }
    }
  }
}
过滤和拍寻
GET /heima/_search
{
    "query":{
        "bool":{
            "must":{ "match": { "title": "小米手机" }},
            "filter":{
                "range":{"price":{"gt":2000.00,"lt":3800.00}}
            }
        }
    }
      "sort": [  //排序
      { "price": { "order": "desc" }},//如果价格相同 根据_id排序
      { "_id": { "order": "desc" }}
    ]
}
获取映射关系
GET /my_index/_mapping

定义新的映射
PUT /my_index
{
  "mappings": {
    "properties": {
      "age":{"type":"integer"},
      "email":{"type":"keyword"}
    }
  }
}
在已存在的索引中添加类型
PUT /my_index/_mapping
{
 "properties": {
      "sex":{"type":"integer","index":false}
    }
}
修改已存在的类型
对于已经存在的映射字段,我们不能更新。更新必须创建新的索引进行数据迁移

往my_index中添加三条数据

POST /my_index/_doc/zhangsan             
{
    "age":35,
    "email":"zhengwenqiang@mail.hisense.com.cn",
    "sex":1
   
}

POST /my_index/_doc/lisi             
{
    "age":35,
    "email":"lisi@mail.hisense.com.cn",
    "sex":1
   
}

POST /my_index/_doc/wangwu             
{
    "age":35,
    "email":"wangwu@mail.hisense.com.cn",
    "sex":1
   
}
根据字符串查找
GET /my_index/_search
{
  "query": {
    "query_string": {
      "query": "lisi@mail.hisense.com.cn"
    }
  }
}

GET /my_index/_search
{
  "query": {
    "term": {
      "email": "wangwu"
    }
  }
}

添加日期类型字段
PUT /my_index1
{
  "mappings": {
    "properties": {
      "age":{"type":"integer"},
      "email":{"type":"keyword"},
      "date":{"type":"date","format": "MMM DD YYYY"}
    }
  }
}

POST /my_index1/goods/                    
{
     "age":35,
    "email":"zhengwenqiang@mail.hisense.com.cn",
    "date":"Oct 25 2013"
   
}
es不是获取所有列,获取指定列
GET /my_index1/_search
{
  "query": {
    "match_all": {}
  },
  "_source": ["date"]
  
  
}
指定id查找
GET my_index/_search
{
  "query": {
    "ids":{
      "values": ["zhangsan","lisi"]
    }
  }
}
分页查询
GET my_index/_search
{
  "from": 0,
  "size": 4
}
排序
GET my_index/_search
{
  "sort": [
  
    {
      "email": "asc"
    }
  ]
}
term与match的区别,term是精确查找,match是分词查找
bool查询
GET /my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "email": "zhengwenqiang@mail.hisense.com.cn"
          }
        }
      
      ]
    }
  }
}
前缀查询
GET /my_index/_search
{
  "query": {
    "prefix": {
        "email": "wangwu"   
    }
  }
  
}
通配符查询
GET /my_index/_search
{
  "query": {
    "wildcard": {
     "email": "*hisense*"
    }
  }
  
}

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值