DSL语句列表——范例

POST /_analyze
{
  "text": "hello world",
  "analyzer": "standard"
}


POST /_analyze
{
  "text": "我要买一部华为手机",
  "analyzer": "ik_smart"
}

POST /_analyze
{
  "text": "我要买一部华为手机",
  "analyzer": "ik_max_word"
}

GET /_analyze
{
  "text": "传智播客的黑马程序员学习java太棒了,奥利给!",
  "analyzer": "ik_max_word"
}


# 创建索引库
PUT /heima
{
  "mappings": {
    "properties": {
      "info":{
        "type": "text",
        "analyzer": "ik_smart"
      },
      "email":{
        "type": "keyword",
        "index": false
      },
      "name":{
        "type": "object",
        "properties": {
            "firstName":{
              "type": "keyword",
              "index": false
            },
            "lastName":{
              "type": "keyword",
              "index": false
            }
        }
      }
    }
  }
}

# 查询索引库
GET /heima

# 删除索引库
DELETE /heima


# 修改索引库-新增字段
PUT /heima/_mapping
{
  "properties":{
    "age":{
      "type":"long"
    }
  }
}


# 文档操作-新增
POST /heima/_doc/1
{
  "age":20,
  "email":"abc@baidu.com",
  "info":"中国人",
  "name":{
    "firstName":"赵",
    "lastName":"云"
  }
}

# 文档操作-查看
GET /heima/_doc/1


# 文档操作-删除
DELETE /heima/_doc/1


# 文档操作-增量修改
POST /heima/_update/1
{
  "doc": {
    "age":21,
    "email":"xxxxx@126.com"
  }
}

# Restclient - 创建酒店数据库
PUT /hotel
{
  "mappings": {
    "properties": {
      "id":{
        "type": "keyword"
      },
      "name":{
        "type": "text",
        "analyzer": "ik_max_word",
        "copy_to": "all"
      },
      "address":{
        "type": "keyword"
      },
      "price":{
        "type": "integer"
      },
      "score":{
        "type": "integer"
      },
      "brand":{
        "type": "keyword",
        "copy_to": "all"
      },      
      "city":{
        "type": "keyword"
      }, 
      "starName":{
        "type": "keyword"
      }, 
      "business":{
        "type": "keyword",
        "copy_to": "all"
      }, 
      "pic":{
        "type": "keyword"
      },
      "location":{
        "type": "geo_point"
      },
      "all":{
        "type": "text",
        "analyzer": "ik_max_word"
      }
    }
  }
}


GET /hotel

DELETE /hotel

GET /hotel/_doc/36934


# 查询-无条件查询(查询所有)
GET /hotel/_search
{
  "query": {
    "match_all": {}
  }
}

# 查询-全文检索查询 - match (查询酒店名称中包含‘如家’的酒店数据)
GET /hotel/_search
{
  "query": {
    "match": {
      "all": "外滩"
    }
  }
}

# 查询-全文检索查询 - multi_match (多字段查询)
GET /hotel/_search
{
  "query": {
    "multi_match": {
      "query": "外滩",
      "fields": ["name","brand","business"]
    }
  }
}

GET /hotel/_search
{
  "query": {
    "match": {
      "all": "外滩"
    }
  }
}

# 查询-精确查询(不分词) - term 词条查询
GET /hotel/_search
{
  "query": {
    "term": {
      "city": {
        "value": "中国北京"
      }
    }
  }
}


# 查询-精确查询(不分词) - range范围查询
GET /hotel/_search
{
  "query": {
    "range": {
      "price": {
        "gte": 100,
        "lte": 200
      }
    }
  }
}


# 查询-地理查询
GET /hotel/_search
{
  "query": {
    "geo_distance":{
      "location" : "31.047235, 121.46234",
      "distance":"15km"
    }
  }
}



# 查询-全文检索查询
GET /hotel/_search
{
  "query": {
    "match": {
      "all": "外滩"
    }
  }
}


# 查询-复合查询 - 函数算分查询
GET /hotel/_search
{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "all": "外滩"
        }
      },
      "functions": [
        {
          "filter": {
            "term": {
              "brand": "如家"
            }
          },
          "weight":10
        }
      ],
      "boost_mode": "sum"
    }
  }
}

# 查询-复合查询 - 布尔查询
GET /hotel/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "如家"
          }
        }
      ],
      "must_not": [
        {
          "range": {
            "price": {
              "gt": 400
            }
          }
        }
      ],
      "filter": [
        {
          "geo_distance": {
            "distance": "10km",
            "location":"31.21,121.5"
          }
        }
      ]
    }
  }
}

#结果处理- 排序 
GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "price": {
        "order": "asc"
      }
    }
  ]
}


#结果处理- 排序 (简写语法)
GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "price": "asc"
    }
  ]
}


#结果处理- 排序 (多字段排序)
GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "price": "asc",
      "score": "desc"
    }
  ]
}


#结果处理- 排序 (距离排序)
GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "_geo_distance": {
        "location": "22.642729, 114.202899",
        "order": "asc",
        "unit": "km"
      }
    }
  ]
}


#结果处理- 分页
GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "from": 2,
  "size": 2
}

GET /hotel/_search
{
  "query": {
    "match_all": {}
  },
  "from": 10000,
  "size": 2
}



#查询结果处理-高亮
GET /hotel/_search
{
  "query": {
    "match": {
      "name": "如家"
    }
  },
  "highlight": {
    "fields": {
      "name": {
        "pre_tags": "<em>",
        "post_tags": "</em>"
      }
    }
  }
}


#查询结果处理-高亮
GET /hotel/_search
{
  "query": {
    "match": {
      "all": "外滩"
    }
  },
  "highlight": {
    "fields": {
      "name": {
        "pre_tags": "<em>",
        "post_tags": "</em>",
        "require_field_match": "false"
      }
    }
  }
}


GET /hotel/_search
{
  "query": {
    "term": {
      "city": "北京"
    }
  },
  "highlight": {
    "fields": {
      "name": {
        "pre_tags": "<em>",
        "post_tags": "</em>",
        "require_field_match": "false"
      }
    }
  }
}


POST /hotel/_update/36934
{
	"doc":{
		"isAD": true
	}
}

POST /hotel/_update/38609
{
	"doc":{
		"isAD": true
	}
}

# 7天连锁酒店(上海宝山路地铁站店)
GET /hotel/_doc/36934

# 速8酒店(上海赤峰路店)
GET /hotel/_doc/38609














  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Kibana是一个用于数据可视化和分析的开工具,它提供了一个基于Web的界面,可以与Elasticsearch进行交互。Kibana DSL(Domain Specific Language)是Kibana提供的一种查询语言,用于构建复杂的搜索和过滤条件。 Kibana DSL语句主要用于构建查询和过滤条件,以便从Elasticsearch中检索所需的数据。以下是一些常用的Kibana DSL语句: 1. match语句:用于执行全文本搜索,匹配指定字段中包含某个词或短语的文档。 例如:`GET /index/_search { "query": { "match": { "field": "keyword" } } }` 2. term语句:用于精确匹配指定字段中的值。 例如:`GET /index/_search { "query": { "term": { "field": "value" } } }` 3. range语句:用于匹配指定字段中的范围值。 例如:`GET /index/_search { "query": { "range": { "field": { "gte": "start", "lte": "end" } } } }` 4. bool语句:用于组合多个查询条件,支持逻辑运算符(must、must_not、should)。 例如:`GET /index/_search { "query": { "bool": { "must": [ { "match": { "field1": "value1" } }, { "match": { "field2": "value2" } } ] } } }` 5. filter语句:用于过滤查询结果,不会影响相关性评分。 例如:`GET /index/_search { "query": { "bool": { "filter": { "term": { "field": "value" } } } } }` 这些只是Kibana DSL语句的一部分,还有其他更多的语句和功能可以用于构建复杂的查询和过滤条件。你可以根据具体的需求来选择和组合这些语句,以实现你想要的数据检索和分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值