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
DSL语句列表——范例
最新推荐文章于 2024-02-18 09:53:28 发布