GET _search
{
"query": {
"match_all": {}
}
}
GET /_analyze
{
"analyzer": "ik_smart",
"text": "我爱北京天安门"
}
# 创建表
PUT /user
{
"mappings": {
"properties": {
"age": {
"type": "integer",
"index": true
},
"info": {
"type": "text",
"analyzer": "ik_smart"
},
"email": {
"type": "keyword"
},
"name": {
"type": "object",
"properties": {
"firstName": {
"type": "keyword"
},
"lastName": {
"type": "keyword"
}
}
}
}
}
}
#查看索引库
GET /hotel
#删除索引库
DELETE /user
#修改索引库
PUT /user/_mapping
{
"properties": {
"weight": {
"type": "double"
}
}
}
#文档操作
#新建文档
POST /user/_doc/
{
"age":30,
"email":"张@qq.com",
"info":"JAVA高级程序员",
"name":{
"firstName":"张",
"lastName": "123"
},
"weight":"75"
}
#查询索引库所有数据
GET /user/_search
{
"query": {
"match_all": {}
}
}
#查询某一个文档数据
GET /user/_doc/1
#删除某一个文档数据
DELETE /user/_doc/lDD-FJMBA6ani3V3HjCM
#修改文档数据
#全局修改
PUT /user/_doc/1
{
"age":30,
"email":"[email protected]",
"info":"JAVA高级程序员",
"name":{
"firstName":"蒋",
"lastName":"欢欢"
},
"weight":"75"
}
#局部修改
POST /user/_update/1
{
"doc": {
"age":66
}
}
#创建hotel索引库
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",
"copy_to": "all"
},
"starName":{
"type": "keyword",
"copy_to": "all"
},
"business":{
"type": "keyword"
},
"location":{
"type": "geo_point"
},
"pic":{
"type": "keyword",
"index": false
},
"isAd":{
"type": "text"
},
"all":{
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
GET /hotel
DELETE /hotel
#查询索引库所有数据
GET /hotel/_search
{
"query": {
"match_all": {}
}
}
#全文检索的match查询
GET /hotel/_search
{
"query": {
"match": {
"all": "如家"
}
}
}
#全文检索的multi_match查询
GET /hotel/_search
{
"query": {
"multi_match": {
"query": "如家",
"fields": ["brand","city","name"]
}
}
}
#精确查询term
GET /hotel/_search
{
"query": {
"term": {
"brand": {
"value": "丽笙"
}
}
}
}
#精确查询range
GET /hotel/_search
{
"query": {
"range": {
"price": {
"gte": 200,
"lte": 300
}
}
}
}
#地理坐标查询 geo_distance
GET /hotel/_search
{
"query": {
"geo_distance":{
"distance": "1.5km",
"location": "31.21,121.5"
}
}
}
#复合型查询:function_score---广告置顶
GET /hotel/_search
{
"query": {
"function_score": {
"query": {
"match": {
"all": "如家"
}
},
"functions": [
{
"filter": {
"range": {
"price": {
"gte": 300,
"lte": 450
}
}
},
"weight": 10
}
],
"boost_mode": "multiply"
}
}
}
GET /hotel/_search
{
"sort": [
{
"price": {
"order": "desc"
}
},
{
"_geo_distance": {
"location": "31.25,121.5",
"order": "asc"
}
}
]
}
}
GET /hotel/_search---广告置顶
{
"query": {
"function_score": {
"query": {
"match": {
"all": "如家"
}
},
"functions": [
{
"filter": {
"term": {
"city": "北京"
}
},
"weight": 10
}
]
}
}
}
GET /hotel/_search
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
],
"filter": [
{
"geo_distance": {
"distance": "10km",
"location": {
"lat": 31.21,
"lon": 121.5
}
}
}
]
}
}
}
GET /hotel/_search
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
],
"filter": [
{
"term": {
"city": "北京"
}
},
{
"term": {
"brand": "如家"
}
}
]
}
},
"sort": [
{
"_geo_distance": {
"location": {
"lat": 31.25,
"lon": 121.5
},
"order": "asc"
}
},
{
"price": {
"order": "desc"
}
}
],
"highlight": {
"fields": {
"name": {
"pre_tags": "<em>",
"post_tags": "</em>",
"require_field_match": "false"
}
}
}
}
#结果集排序
GET /hotel/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"price": {
"order": "desc"
}
}
]
}
GET /hotel/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"_geo_distance": {
"location": {
"lat": 31.21,
"lon": 121.5
},
"order": "asc"
}
}
]
}
GET /hotel/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"score": {
"order": "desc"
},
"price": {
"order": "asc"
}
}
]
}
GET /hotel/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"isAD": {
"order": "desc"
}
}
]
}
GET /hotel/_search
{
"query": {
"match_all": {}
},
"from": 191,
"size": 10,
"sort": [
{
"price": {
"order": "asc"
}
}
]
}
GET /hotel/_search
{
"query": {
"match": {
"name": "如家"
}
},
"highlight": {
"fields": {
"name": {
"pre_tags": "<em>",
"post_tags": "</em>"
}
}
}
}
GET /hotel/_search
{
"query": {
"match": {
"brand": "如家"
}
},
"highlight": {
"fields": {
"name": {
"pre_tags": "<em>",
"post_tags": "</em>",
"require_field_match": "false"
}
}
}
}
POST /hotel/_update/197837109
{
"doc": {
"isAD": true
}
}
POST /hotel/_update/1557882030
{
"doc": {
"isAD": true
}
}
POST /hotel/_update/197492277
{
"doc": {
"isAD": true
}
}
POST /hotel/_update/200214824
{
"doc": {
"isAD": true
}
}
GET /hotel/_search
{
"query": {
"match_all": {}
},
"from": 191,
"size": 10
}
GET /hotel/_search
{
"query": {
"match": {
"all": "上海"
}
}
}
标签:search,Elastic,GET,type,hotel,Dev,query,Tools,match
From: https://www.cnblogs.com/xwdzj/p/18545217