#获取所有索引信息
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"
]
}
}
}
DSL语句的使用
于 2022-12-30 02:36:07 首次发布