Elasticsearch7.13.3的DSL常见语法详解

1.创建索引

PUT /employee
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1
  },
  "mappings": {
    "properties": {
      "info":{
        "type": "text"
      },
      "email":{
        "type": "keyword",
        "index": "false"
      },
      "name":{
        "properties": {
          "firstName": {
            "type": "keyword"
          }
        }
      }
  }
  }
}

2 添加索引字段

PUT /employee/_mapping
{
   "properties":{
        "id":{
            "type":"integer"
        }
    }
}

3 删除索引字段

PUT employee/_update_by_query
{
 "script": {
    "source": "ctx._source.remove(\"id\")",
    "lang": "painless"
  }
}

4 #数据迁移

POST _reindex
{
  "source": {
    "index": "employee"
  },
  "dest": {
    "index": "course"
  }
}

5 删除索引

DELETE employee

6获取索引映射

GET /employee/_mapping

7 插入文档

POST /employee/_doc/6
{
  "id":6, 
 "info":"33333444444445555",
 "email":"11222255555.qq.com"
}

8 查询 索引文档根据id

GET /employee/_doc/1

9查询全部

GET employee/_search
{
  "query":{
    "match_all": {
      
    }
  },
   "size": 100
}

10 根据term查询

GET /employee/_search
{
  "query": {
    "term": {
      "id": { 
        "value": "6" 
      }
    }
  }
}

11 范围查询(range)

GET /employee/_search
{
  "query": {
     "range": {
      "id": { 
        "gte": 10,
        "lte": 232
      }
    }
  }
}

12 前缀查询(prefix)

GET /employee/_search
{
  "query": {
    "prefix": {
      "info": { 
        "value": "冯敏"
      }
    }
  }
}

13 通配符查询

GET /employee/_search
{
  "query": {
    "wildcard": {
      "info": { 
        "value": "冯敏*" 
      }
    }
  }
}

14 多_id查询(ids)

GET /employee/_search
{
   "query": {
    "ids": {
      "values": [2] 
    }
  }
}

15 模糊查询常用于keyword类型的字段

GET /employee/_search
{
    "query": {
    "fuzzy": {
      "info": "冯敏" 
    }
  }
}

其他一些逻辑词
#布尔(组合)查询(bool)
#must 相当于&& 同时成立
#should 相当于||成立一个即可
#must_not 相当于!不能满足任何一个

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值