我正在尝试创建一个查询,该查询返回在该日期(或日期范围)没有预订或根本没有预订的可用产品。这让我疯狂。
这是我当前的索引设置映射:
{
"development_product_instances" : {
"aliases" : { },
"mappings" : {
"product_instance" : {
"properties" : {
"reservations" : {
"type" : "nested",
"properties" : {
"end_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
},
"start_date" : {
"type" : "date",
"format" : "yyyy-MM-dd"
}
}
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1503327829680",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "9b9BhF-ITta2dlCKRLrnfA",
"version" : {
"created" : "2040499"
}
}
},
"warmers" : { }
}
}
和查询:
{
bool: {
should: [
{
nested: {
path: "reservations",
filter: {
bool: {
must_not: [
{
range:
{
"reservations.start_date":
{
gte: start_date,
lte: end_date
}
}
},
{
range:
{
"reservations.end_date":
{
gte: start_date,
lt: end_date
}
}
}
]
}
}
}
},
{
not: {
nested: {
path: "reservations",
filter: {
match_all: {}
}
}
}
}
]
}
}
当有多个预订时,它会返回所有预订。
我希望有人能看到那里的错误。也许我在大局中遗漏了一些东西。