我需要根据时间戳搜索我的索引。
文档具有以下字段组合:
或者
伪查询:。对于给定的时间戳,我希望返回 id 匹配的所有文档,并且:
timestamp >= start_time && timestamp < end_time
但如果没有 end_time 字段,则查询需要是这样的:
(not exists end_time) && (timestamp > start_time)
弹性查询。这就是我要发疯的地方。我无法获得与上述伪查询等效的弹性查询。也许我以错误的方式接近它(完全有可能)。这是我所拥有的:
{
"query": {
"bool": {
"must": [
{
"term": {
"id_s": "SomeIdValue"
}
},
{
"bool": {
"should": [
{
"must": [
{
"must_not": [
{
"exists": {
"field": "end_time_dt"
}
}
]
},
{
"range": {
"start_time_dt": {
"lte": "2019-07-12T03:20:22"
}
}
}
]
},
{
"filter": [
{
"range": {
"start_time_dt": {
"lte": "2019-07-12T03:20:22"
}
}
},
{
"range": {
"end_time_dt": {
"gte": "2019-07-12T03:20:22"
}
}
}
]
}
]
}
}
]
}
}
}
但这给了我 [must] query malformed, no start_object after query name
我如何构造这个查询?我在正确的轨道上吗?
提前致谢!
您的查询在语法上是错误的。正确的查询是:
{
"query": {
"bool": {
"filter": [
{
"term": {
"id_s": "SomeIdValue"
}
},
{
"bool": {
"should": [
{
"bool": {
"must_not": [
{
"exists": {
"field": "end_time_dt"
}
}
],
"must": [
{
"range": {
"start_time_dt": {
"lte": "2019-07-12T03:20:22"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"range": {
"start_time_dt": {
"lte": "2019-07-12T03:20:22"
}
}
},
{
"range": {
"end_time_dt": {
"gte": "2019-07-12T03:20:22"
}
}
}
]
}
}
]
}
}
]
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句