我在弹性搜索中有以下格式的数据(来自意义)
POST slots/slot/1
{
locationid:"1",
roomid:"10",
starttime: "08:45"
}
POST slots/slot/2
{
locationid:"1",
roomid:"10",
starttime: "09:00"
}
POST slots/slot/3
{
locationid:"2",
roomid:"100",
starttime: "08:45"
}
POST slots/slot/4
{
locationid:"2",
roomid:"101",
starttime: "09:00"
}
POST slots/slot/5
{
locationid:"3",
roomid:"200",
starttime: "09:30"
}
简而言之,数据采用以下格式。
A位置有多个房间,每个房间有15分钟的多个插槽。因此Room10的1号槽位于8:45开始,09:00结束,同一房间的1号槽位于09:00开始,于09:15结束
Locationid RoomId Starttime
--------------------------------------
1 10 08:45
1 10 09:00
2 100 08:45
2 101 09:00
3 200 09:30
我正在尝试编写一个查询/过滤器,它会为我提供一个有两个或三个插槽的房间的所有位置。
例如查找具有08:45插槽和09:00插槽的位置(可配置) 答案应该只是位置1 不应该是位置2,因为房间100有08:45插槽但不是09:00插槽。 101室有09:00,但没有08:45插槽
答案 0 :(得分:0)
我认为这不是最好的方法,而是我尝试的答案
POST slots/slot/_search?pretty=true&search_type=count
{
"facets": {
"locationswithslots": {
"terms": {
"field": "locationid",
"script" : "term + \"_\" + _source.roomid",
"size": 10
},
"facet_filter":
{
"terms":
{
"starttime":
[
"08:45",
"09:00"
]
}
}
}
}
}
这给出了如下答案
{
"took": 12,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 0,
"hits": []
},
"facets": {
"locationswithslots": {
"_type": "terms",
"missing": 0,
"total": 4,
"other": 0,
"terms": [
{
"term": "1_10",
"count": 2
},
{
"term": "2_101",
"count": 1
},
{
"term": "2_100",
"count": 1
}
]
}
}
}
现在我需要找出一种方法来过滤返回计数2的方面,因为我在过滤器中传入2个插槽。
还有其他选择吗?