2.7.6 指定返回的字段
GET /lib3/user/_search { "_source": ["address","name"], "query": { "match": { "interests": "changge" } } }
2.7.7控制加载的字段
GET /lib3/user/_search { "query": { "match_all": {} },
"_source": {
"includes": ["name","address"],
"excludes": ["age","birthday"]
}
}
使用通配符*
GET /lib3/user/_search { "_source": { "includes": "addr*", "excludes": ["name","bir*"]
},
"query": {
"match_all": {}
}
}
2.7.8 排序
使用sort实现排序: desc:降序,asc升序
GET /lib3/user/_search { "query": { "match_all": {} }, "sort": [ { "age": { "order":"asc" } } ]
}
GET /lib3/user/_search { "query": { "match_all": {} }, "sort": [ { "age": { "order":"desc" } } ]
}
2.7.9 前缀匹配查询
GET /lib3/user/_search { "query": { "match_phrase_prefix": { "name": { "query": "zhao" } } } }
2.7.10 范围查询
range:实现范围查询
参数:from,to,include_lower,include_upper,boost
include_lower:是否包含范围的左边界,默认是true
include_upper:是否包含范围的右边界,默认是true
GET /lib3/user/_search { "query": { "range": { "birthday": { "from": "1990-10-10", "to": "2018-05-01" } } } }
GET /lib3/user/_search { "query": { "range": { "age": { "from": 20, "to": 25, "include_lower": true, "include_upper": false } } } }
2.7.11 wildcard查询
允许使用通配符* 和 ?来进行查询
*代表0个或多个字符
?代表任意一个字符
GET /lib3/user/_search { "query": { "wildcard": { "name": "zhao*" } } }
GET /lib3/user/_search { "query": { "wildcard": { "name": "li?i" } } }
2.7.12 fuzzy实现模糊查询
value:查询的关键字
boost:查询的权值,默认值是1.0
min_similarity:设置匹配的最小相似度,默认值为0.5,对于字符串,取值为0-1(包括0和1);对于数值,取值可能大于1;对于日期型取值为1d,1m等,1d就代表1天
prefix_length:指明区分词项的共同前缀长度,默认是0
max_expansions:查询中的词项可以扩展的数目,默认可以无限大
GET /lib3/user/_search { "query": { "fuzzy": { "interests": "chagge" } } }
GET /lib3/user/_search { "query": { "fuzzy": { "interests": { "value": "chagge" } } } }
2.7.13 高亮搜索结果
GET /lib3/user/_search { "query":{ "match":{ "interests": "changge" } }, "highlight": { "fields": { "interests": {} } } }
2.8 Filter查询
filter是不计算相关性的,同时可以cache。因此,filter速度要快于query。
POST /lib4/items/_bulk {"index": {"_id": 1}}
{"price": 40,"itemID": "ID100123"}
{"index": {"_id": 2}}
{"price": 50,"itemID": "ID100124"}
{"index": {"_id": 3}}
{"price": 25,"itemID": "ID100124"}
{"index": {"_id": 4}}
{"price": 30,"itemID": "ID100125"}
{"index": {"_id": 5}}
{"price": null,"itemID": "ID100127"}
####2.8.1 简单的过滤查询
GET /lib4/items/_search { "post_filter": { "term": { "price": 40 } } }
GET /lib4/items/_search { "post_filter": { "terms": { "price": [25,40] } } }
GET /lib4/items/_search { "post_filter": { "term": { "itemID": "ID100123" } } }
查看分词器分析的结果:
GET /lib4/_mapping
不希望商品id字段被分词,则重新创建映射
DELETE lib4
PUT /lib4 { "mappings": { "items": { "properties": { "itemID": { "type": "text", "index": false } } } } }
标签:返回,search,GET,指定,user,lib3,query,2.7,es From: https://blog.51cto.com/u_16237074/8329141