2021-01-01

创建索引成功描述

PUT school
创建一条数据

PUT /school/test1/1
{
  "name":"狂神说",
  "age":4
}

命令详解:
PUT /索引名/类型名/文档ID
{
}

按指定的mapping创建index

PUT test1
{
  "mappings": {
    "properties": {
      "name":{
        "type": "text"
      },
      "age":{
        "type": "long"
      },
      "birthday":{
        "type": "date"
      }
    }
  }
}

获取index信息

GET test1

在这里插入图片描述

查看索引列表

GET _cat/indices?v

插入数据

PUT test1/_doc/1
{
  "name":"张三1",
  "age":25,
  "birthday":"1987-11-29"
}

更新数据

POST test1/_doc/1/_update
{
  "doc":{
    "name":"李四"
  }
}

删除索引

DELETE school

精确查询

GET test1/_doc/_search?q=name:"李四"
GET test1/_search?q=name:"狂神说"

复杂查询

POST test1/_search
{
  "query": {
    "match": {
      "name": "李"
    }
  }
}

查询 并且过滤字段

POST test1/_search
{
  "query": {
    "match": {
      "name": "李"
    }
  },
  "_source": ["name","age"]
  
}

排序

POST test1/_search
{
  "query": {
    "match": {
      "name": "狂神"
    }
  },
  "_source": ["name","age"],
  "sort": [
    {
      "age": {
        "order": "asc"
      }
    }
  ]
  
}

分页

POST test1/_search
{
  "query": {
    "match": {
      "name": "狂神"
    }
  },
  "_source": ["name","age"],
  "sort": [
    {
      "age": {
        "order": "asc"
      }
    }
  ],
  "from": 0,
  "size":2
  
}

多条件bool查询

POST test1/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "狂神说"
          }
        },
        {
          "match": {
            "age": 25
          }
        }
      ]
    }
  }
}

多条件查询,带过滤

POST test1/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "狂神说"
          }
        }
      ],
      "filter": [
        {
          "range": {
            "age": {
              "gte": 10,
              "lte": 30
            }
          }
        }
      ]
    }
  }
}

查询高亮显示

GET test1/_search
{
  "query": {
    "match": {
      "name": "狂神"
    }
  },
  "highlight": {
    "fields": {
      "name": {}
    }
  }
}

查询高亮显示,自定义标签

GET test1/_search
{
  "query": {
    "match": {
      "name": "狂神"
    }
  },
  "highlight": {
    "pre_tags": "<p class='key' style='color:red'>", 
    "post_tags": "</p>", 
    "fields": {
      "name": {}
    }
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值