我的搜索結果存在問題。彈性搜索 - 與範圍數組嵌套匹配
我有以下我的索引映射:
{
"index": {
"mappings": {
"shop": {
"properties": {
"about": {
"type": "text"
},
"address": {
"type": "text"
},
"description": {
"type": "text"
},
"email": {
"type": "text"
},
"location": {
"type": "geo_point"
},
"name": {
"type": "text"
},
"operationHours": {
"type": "nested",
"include_in_parent": true,
"properties": {
"dayOfWeek": {
"type": "long"
},
"timeRanges": {
"type": "nested",
"include_in_parent": true,
"properties": {
"from": {
"type": "long"
},
"to": {
"type": "long"
}
}
}
}
},
"phone": {
"type": "text"
},
"profileImageName": {
"type": "text"
}
}
}
}
}
}
我加入以下文件:
{
"operationHours": [
{
"timeRanges": [
{
"to": 720,
"from": 600
},
{
"to": 1500,
"from": 840
}
],
"dayOfWeek": 0
},
{
"timeRanges": [
{
"to": 720,
"from": 700
},
{
"to": 960,
"from": 840
}
],
"dayOfWeek": 2
},
{
"timeRanges": [
{
"to": 720,
"from": 600
},
{
"to": 1500,
"from": 840
}
],
"dayOfWeek": 4
},
{
"timeRanges": [
{
"to": 720,
"from": 600
},
{
"to": 1500,
"from": 840
}
],
"dayOfWeek": 5
},
{
"timeRanges": [
{
"to": 720,
"from": 600
},
{
"to": 1500,
"from": 840
}
],
"dayOfWeek": 6
},
{
"timeRanges": [
{
"to": 720,
"from": 600
},
{
"to": 1500,
"from": 840
}
],
"dayOfWeek": 7
}
],
"location": {
"lon": "-68.72307",
"lat": "25.463178"
},
"profileImageName": "ACRUEX.jpg",
"address": "620 Classon Avenue, Hendersonville, Mississippi, 4076",
"description": "Tempor culpa dolore Lorem fugiat dolore esse. Ullamco ipsum dolore amet dolor laboris eu nisi consequat Lorem non mollit minim exercitation. Voluptate ipsum mollit culpa aute sunt consectetur minim anim cupidatat dolor quis labore do amet. Non id voluptate dolore nostrud laboris voluptate consequat aliqua labore.",
"about": "Non labore culpa do consectetur fugiat velit. Reprehenderit cupidatat nulla veniam exercitation adipisicing amet. Mollit irure voluptate dolor est veniam nulla fugiat elit. Non et deserunt excepteur non officia enim non voluptate qui amet adipisicing quis enim exercitation.",
"email": "[email protected]",
"phone": "+1 (833) 575-2171",
"name": "ISOPOP"
}
然後,我使用以下查詢獲取運行時間範圍大於或等於指定時間的文檔(示例中爲730)。
730表示從午夜開始的分鐘數,即730是12:10 pm。
GET index/shop/1/_explain
{
"query": {
"nested" : {
"path" : "operationHours",
"query": {
"bool" : {
"must" : [
{ "match" : { "operationHours.dayOfWeek" : 2 } },
{ "range": {"operationHours.timeRanges.from": { "lte": 730 }}},
{ "range": {"operationHours.timeRanges.to": { "gt": 730 }}}
]
}
}
}
}
}
它配備了一個比賽,它不應該做的,作爲「730」落下700至720和840的範圍內,以960
任何幫助犯規值至於我哪裏出錯會很好。
你有什麼想說的,你能不能請重新檢查在查詢自己的價值觀。 – user3775217
什麼林試圖說,是我想返回的文件必須和範圍覆蓋我通過一個int值。例如,上面的文檔對於dayOfWeek = 2的值爲700和720。如果我通過710,則必須退回文件。如果我通過730,則不得退回文件。 – TheDaveJay