GET _search
{
“query”: {
“match_all”: {}
}
}

#模拟请求
GET /

# 测试分词器
POST /_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”
},
“lastName”:{
“type”:”keyword”
}
}
}
}
}
}

# 查询
GET /heima

# 修改索引库,添加新字段
PUT /heima/_mapping
{
“properties”:{
“age”:{
“type”:”integer”
}
}
}

# 删除
DELETE /heima

# 插入一个文档
POST /heima/_doc/1
{
“info”:”黑马程序员Java讲师”,
“email”:”zy@itcast.cn”,
“name”:{
“firstName”:”云”,
“lastName”:”赵”
}
}

# 查询文档
GET /heima/_doc/1

# 删除文档
DELETE /heima/_doc/1

#全量修改文件
PUT /heima/_doc/1
{
“info”:”黑马程序员Java讲师”,
“email”:”zhaoyun@itcast.cn”,
“name”:{
“firstName”:”云”,
“lastName”:”赵”
}
}

# 局部修改文档字段
POST /heima/_update/1
{
“doc”:{
“email”:”zyun@itcast.cn”
}
}

# 酒店的mapping
PUT /hotel
{
“mappings”: {
“properties”: {
“id”:{
“type”:”keyword”
},
“name”:{
“type”: “text”,
“analyzer”: “ik_max_word”,
“copy_to”: “all”
},
“address”:{
“type”: “keyword”,
“index”:false
},
“price”:{
“type”:”integer”
},
“score”:{
“type”:”integer”
},
“brand”:{
“type”:”keyword”,
“copy_to”: “all”
},
“city”:{
“type”:”keyword”
},
“starName”:{
“type”:”keyword”
},
“business”:{
“type”:”keyword”,
“copy_to”: “all”
},
“location”:{
“type”: “geo_point”
},
“pic”:{
“type”:”keyword”,
“index”: false
},
“all”:{
“type”:”text”,
“analyzer”: “ik_max_word”
}
}
}
}

GET /hotel/_doc/61083

# 查询所有
Get /hotel/_search
{
“query”:{
“match_all”: {

}
}
}

# match查询
GET /hotel/_search
{
“query”: {
“match”: {
“all”: “外滩”
}
}
}

# multi_match查询
GET /hotel/_search
{
“query”: {
“multi_match”: {
“query”: “如家外滩”,
“fields”: [“brand”,”name”,”business”]
}
}
}

# term查询
GET /hotel/_search
{
“query”: {
“term”: {
“city”: {
“value”: “杭州”
}
}
}
}

# range查询
GET /hotel/_search
{
“query”: {
“range”: {
“price”: {
“gte”: 100,
“lte”: 300
}
}
}
}

# distance查询
GET /hotel/_search
{
“query”: {
“geo_distance”:{
“distance”:”15km”,
“location”:”31.21,121.5″
}
}
}

# function score查询
GET /hotel/_search
{
“query”: {
“function_score”: {
“query”: {
“match”: {
“all”: “外滩”
}
},
“functions”: [
{
“filter”: {
“term”: {
“brand”: “如家”
}
},
“weight”: 10
}
],
“boost_mode”: “sum”
}
}
}

# bool 查询
GET /hotel/_search
{
“query”: {
“bool”: {
“must”: [
{
“match”: {
“name”: “如家”
}
}
],
“must_not”: [
{
“range”: {
“price”: {
“gt”: 400
}
}
}
],
“filter”: [
{
“geo_distance”: {
“distance”: “10km”,
“location”: {
“lat”: 31.21,
“lon”: 121.5
}
}
}
]
}
}
}

# sort排序
GET /hotel/_search
{
“query”: {
“match_all”: {}
},
“sort”: [
{
“FIELD”: {
“order”: “desc”
}
}
]
}

# sort排序
GET /hotel/_search
{
“query”: {
“match_all”: {}
},
“sort”: [
{
“score”: {
“order”: “desc”
},
{
“price”:”asc”
}
}
]
}

# 找到121.612282,31.034661周围的酒店,距离升序排序
GET /hotel/_search
{
“query”: {
“match_all”: {}
},
“sort”: [
{
“_geo_distance”: {
“location”: {
“lat”: 31.034661,
“lon”: 121.612282
},
“order”: “asc”,
“unit”:”km”
}
}
]
}

# 分页查询
GET /hotel/_search
{
“query”: {
“match_all”: {}
},
“sort”: [
{
“price”: {
“order”: “asc”
}
}
],
“from”: 20,
“size”: 10
}

# 高亮查询,默认情况下,ES搜索字段必须与高亮字段保持一致
GET /hotel/_search
{
“query”: {
“match”: {
“all”: “如家”
}
},
“highlight”: {
“fields”: {
“name”: {
“require_field_match”: “false”
}
}
}
}

原文地址:http://www.cnblogs.com/zhfblogs/p/16887025.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性