全文检索查询,会对用户输入的内容分词,常用于收所框首搜索
#match 单字段查询
GET /hotel/_search
{
"query": {
"match": {
"all": "如家外滩"
}
}
}
#multi_match 组合字段搜索
GET /hotel/_search
{
"query": {
"multi_match": {
"query": "外滩如家",
"fields": ["brand","name","business"]
}
}
}
精确查询一般是查找keyword,数值。日期,Boolean等类型字段,所以不会对字段进行分词
# term 准确查询
GET /hotel/_search
{
"query": {
"term": {
"city": {
"value": "上海"
}
}
}
}
# range 范围查询
GET /hotel/_search
{
"query": {
"range": {
"price": {
"gte": 1000,
"lte": 3000
}
}
}
}
代码
# funtion scoure 查询
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": {
"lat": 31.21,
"lon": 121.5
}
}
}
]
}
}
}
常规代码
#排序
GET /hotel/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"score": "desc"
},
{
"price": "asc"
}
]
}
地理位置排序
#添加索引字段
PUT /hotel/_mapping
{
"properties":{
"isAD":{
"type":"keyword",
"index" : "false"
}
}
}
限定聚合范围
嵌套聚合