span_within
ES区间搜索query包含两部分:little和big;只有little term出现在big term之间的文档才会被返回
GET search_data/_search
{
"size": 120,
"_source": "title",
"query": {
"span_within": {
"little": {
"span_term": {
"title": {
"value": "大气"
}
}
},
"big": {
"span_near": {
"clauses": [
{
"span_term": {
"title": {
"value": "高端"
}
}
} ,
{
"span_term": {
"title": {
"value": "商务"
}
}
} ,
{
"span_term": {
"title": {
"value": "招聘"
}
}
}
],
"slop": 5,
"in_order": true
}
}
}
}
}
结果:
{
"_index" : "search_data",
"_type" : "_doc",
"_id" : "431983",
"_score" : 13.440511,
"_ignored" : [
"xk_last_create_time"
],
"_source" : {
"title" : "高端商务大气企业招聘"
}
},
{
"_index" : "search_data",
"_type" : "_doc",
"_id" : "1121117",
"_score" : 13.440511,
"_ignored" : [
"xk_last_create_time"
],
"_source" : {
"title" : "高端大气商务企业招聘"
}
}
可以看大"大气"必须出现在“高端”与“招聘”之间,
-
in_order
其中“高端”、“商务”与“招聘”三个关键词在title field中是有序的,如果不关注顺序可将in_order设置为false -
slop
用来控制满足条件的最大term间距,上述query中little+big的term数为4,所以这里的slop不能低于4,否则无结果;如果slop>4那么会允许匹配的文档中在“高端”与“招聘”之间有其它word出现。
网友评论