DSL语句的使用

#获取所有索引信息
GET _cat/indices?v
#删除索引库
DELETE /logstash-dx
#添加索引库
PUT /user/userinfo/_mapping
{
  "properties": {
    "name":{
      "type": "text",
      "analyzer": "ik_smart",
      "search_analyzer": "ik_smart",
      "store": false
    },
    "city":{
      "type": "text",
      "analyzer": "ik_smart",
      "search_analyzer": "ik_smart",
      "store": false
    },
    "age":{
      "type": "long",
      "store": false
    },
    "description":{
      "type": "text",
      "analyzer": "ik_smart",
      "search_analyzer": "ik_smart",
      "store": false
    }
  }
}
#添加文档数据
put user/userinfo/1
{
  "name":"lisi",
  "age":22,
  "city":"chengdu",
  "description":"welcome chengdu"
}
put user/userinfo/2
{
  "name":"zhangsan",
  "age":23,
  "city":"congzhou",
  "description":"welcome congzhou"
}
put user/userinfo/3
{
  "name":"wangwu",
  "age":42,
  "city":"wuhou",
  "description":"welcome wuhou"
}
put user/userinfo/4
{
  "name":"zhangsanfen",
  "age":22,
  "city":"jinniu",
  "description":"welcome jinniu"
}
put user/userinfo/5
{
  "name":"zhaozhilong",
  "age":32,
  "city":"dayi",
  "description":"welcome dayi",
  "address":"chengdu dayi"
}

get /user/userinfo/6
# 修改数据,id=6新建一条数据,删除原数据
put user/userinfo/6
{
  "name":"libai",
  "age":25,
  "city":"chenghua",
  "description":"welcome chenghua"
}
#使用post更新某一个域的数据
post user/userinfo/6/_update
{
  "doc":{
  "name":"yase"
  }
}
#删除数据
delete user/userinfo/5
#查询所有数据
get /user/userinfo/_search
#搜索排序
get /user/userinfo/_search
{
  "query":{
    "match_all": {}
  },
  "sort":[
    {
    "age":{
      "order":"desc"
    }
  }
],
}

#搜索查询并分页
get /user/userinfo/_search
{
  "query":{
    "match_all": {}
  },
  "sort":[
    {
    "age":{
      "order":"desc"
    }
  }
],
"from":0,
"size":2
}

#词项搜索Term
GET /user/userinfo/_search
{
  "query": {
    "term": {
      "city": {
        "value": "congzhou"
      }
    }
  }
}

#多词项搜索
GET /user/userifo/_search
{
 "query": {
   "terms": {
     "city": [
       "congzhou",
       "chengdu"
     ]
   }
 } 
}

#范围过滤搜索
GET /user/userinfo/_search
{
  "query": {
    "range": {
      "age": {
        "gte": 10,
        "lte": 60
      }
    }
  },
  "sort": [
    {
      "age": {
        "order": "asc"
      }
    }
  ]
}
#查询存在address的数据
GET /user/userinfo/_search
{
  "query": {
    "exists":{
      "field":"city"
    }
  }
}

#多条件查询
#must :多个查询条件完全匹配,相当于and
#must_not:多个查询条件的相反匹配,相当于Not
#should:至少一个查询条件匹配,相当于or
GET /user/userinfo/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "city": {
              "value": "chengdu"
            }
          }
        },
        {
          "range": {
            "age": {
              "gte": 10,
              "lte": 30
            }
          }
        }
      ],
      "must_not": [
        {"term": {
          "name": {
            "value": "li"
          }
        }}
      ]
    }
  }
}
#根据某个字符进行搜索
GET user/userinfo/_search
{
  "query": {
    "match": {
      "city": "congzhou"
    }
  }
}

#按前缀搜索
GET /user/userinfo/_search
{
  "query": {
    "prefix": {
      "name": {
        "value": "w"
      }
    }
  }
}

#多个域匹配
#搜索description,city两个域中都包含“changdu”的数据
GET user/userinfo/_search
{
  "query": {
    "multi_match": {
      "query": "chengdu",
      "fields": [
        "city",
        "description"
        ]
    }
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XL's妃妃

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值