1、term词项精确查询
term词项概念:整个语句文字分为一个词
字段类型:
1)主要是keyword类型,其余非text字段部分可用
默认是区分大小写的(es不做任何大小写转换),但可以将term改成match忽略大小写搜索
term数值类型也可以检索,精确匹配类似于相等(使用的是倒排索引来实现的,比mysql要快很多)
2)数据内容有长度限制(2的16次方字节)
GET /example_001/_search
{
"track_total_hits":true,
"query": {
"bool":{
"must": [
{
//match可以忽略大小写进行搜索
//"match": {
// "companyName": "ALIbaba"
// }
//底层实现使用的是倒排索引
"term": {
"companyName.keyword": {
"value": "alibaba"
}
}
}
]
}
}
}
GET /example_001/_search
{
"track_total_hits":true,
"query": {
"bool":{
"must": [
{
//. 范围查找(底层实现使用的是BKD树)
"range": {
"staffNum": {
"gte": 100,
"lte": 1000
}
}
}
]
}
}
}
结果:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.2039728,
"hits" : [
{
"_index" : "example_001",
"_type" : "_doc",
"_id" : "pMp8v3wBMc_gex2mk0bP",
"_score" : 1.2039728,
"_source" : {
"companyName" : "alibaba",
"staffNum" : 5000,
"address" : "hzbj",
"sonCompany" : {
"companyName" : "hema",
"stafffNum" : "500",
"workContent" : "盒马生鲜"
}
}
}
]
}
}
网友评论