【发布时间】:2021-05-23 02:50:21
【问题描述】:
我想知道是否有人可以确认我构造的查询是否正确。
我有一个 User 映射,其中 Transaction 嵌套在用户中,我正在寻找在某个日期之前购买了特定商品的用户。此外,在Transaction 中,我还有line_items,这也是一个嵌套字段。
最初,我构造了以下查询,根据返回的数据,我断定该查询可能不正确。
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "transaction",
"query": {
"nested": {
"path": "transaction.line_items",
"query": {
"bool": {
"must": {
"match": {
"transaction.line_items.barcode": {
"query": "abc123xyz"
}
}
}
}
}
}
}
}
},
{
"nested": {
"path": "transaction",
"query": {
"range": {
"transaction.timestamp": {
"from": null,
"include_lower": true,
"include_upper": true,
"to": "2021-05-14T00:00:00+02:00"
}
}
}
}
}
]
}
}
}
然后我更新了我的查询,现在根据返回的结果我认为查询是正确的。但是,为了避免确认偏差,我想知道是否有人可以解释为什么第二个查询是正确的(假设是正确的)。
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "transaction",
"query": {
"bool": {
"must": [
{
"range": {
"transaction.timestamp": {
"from": null,
"include_lower": true,
"include_upper": true,
"to": "2021-05-16T00:00:00+02:00"
}
}
},
{
"nested": {
"path": "transaction.line_items",
"query": {
"bool": {
"must": {
"match": {
"transaction.line_items.barcode": {
"query": "abc123xyz"
}
}
}
}
}
}
}
]
}
}
}
}
]
}
}
}
【问题讨论】:
标签: elasticsearch nested range-query