我有两个使用父子关系映射的类型文档,映射如下:
{
"venue": {
"properties": {
"id": {
"type": "long",
"index": "not_analyzed"
},
"address": {
"type": "string",
"index": "analyzed"
},
"capacity": {
"type": "integer",
"index": "not_analyzed"
},
"rate_standard": {
"type": "nested",
"properties": {
"rate": {
"type": "double",
"precision_step": 1,
"index": "not_analyzed"
},
"minimum": {
"type": "integer",
"index": "not_analyzed"
}
}
}
}
},
"calendar": {
"_parent": {
"type": "venue"
},
"properties": {
"day": {
"type": "date",
"format": "yyyy-MM-dd",
"precision_step": 1,
"index": "not_analyzed"
},
"is_available": {
"type": "boolean",
"index": "not_analyzed"
},
"rate": {
"type": "double",
"precision_step": 1,
"index": "not_analyzed"
},
"minimum": {
"type": "integer",
"index": "not_analyzed"
}
}
}
}
我想对它们运行查询,如下所示:
is_available = false
,between 2014-01-01 to 2014-12-01
曾尝试构建查询,但它似乎搞乱了嵌套bool查询
{
"query": {
"bool": {
"must": [
{
"range": {
"capacity": {
"gte": 2
}
}
},
{
"match": {
"address": {
"query": "mampang jakarta indonesia",
"operator": "and"
}
}
}
],
"must_not": {
"has_child": {
"type": "calendar",
"query": {
"bool": {
"must": [
{
"term": {
"available": false
}
},
{
"range": {
"day": {
"gte": "2014-01-01",
"lte": "2014-12-01"
}
}
}
],
"must_not": {},
"should": {}
}
}
}
},
"should": {}
}
}
}
答案 0 :(得分:0)
这个似乎有效
{
"query": {
"bool": {
"must": [
{ "range" : {"capacity": { "gte": 2 }} },
{ "match": {"address": { "query" : "mampang jakarta indonesia", "operator" : "and" }} }
],
"must_not": [
{
"has_child": {
"type": "calendar",
"query": {
"bool": {
"must":[
{"term": {"available" : false }},
{"range": {"day": {"gte": "2014-01-01", "lte": "2014-12-01" }}}
]
}
}
}
}
]
}
}
}
仍然不确定这是否是适当的查询来实现