创建索引![成功描述](https://img-blog.csdnimg.cn/20210101203350450.png#pic_center)
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": {}
}
}
}